Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9124765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:38:25+00:00 2026-06-17T06:38:25+00:00

I have a simple model that tracks work leave requests: class LeaveRequest(models.Model): employee =

  • 0

I have a simple model that tracks work leave requests:

class LeaveRequest(models.Model):
    employee = models.ForeignKey(UserProfile)
    supervisor = models.ForeignKey(UserProfile, related_name='+', blank=False, null=False)
    submit_date = models.DateField(("Date"), default=datetime.date.today)
    leave_type = models.CharField(max_length=64, choices=TYPE_CHOICES)
    start_date = models.DateField(("Date"))
    return_date = models.DateField(("Date"))
    total_days = models.IntegerField()
    notes = models.TextField(max_length=1000)

    def __unicode__ (self):
        return u'%s %s' % (self.employee, self.submit_date)

        class Admin: 
                pass

        class Meta:
                ordering = ['-submit_date']

In the view I need a function to calculate the number of days requested. Secondarily, I’ll need a method to count only weekdays, but for now I’ve got the following:

def leave_screen(request, id):
    records = LeaveRequest.objects.filter(employee=id)
    total_days = LeaveRequest.return_date - LeaveRequest.start_date
    tpl = 'vacation/leave_request.html'
    return render_to_response(tpl, {'records': records })

which produces a attribute error

type object 'LeaveRequest' has no attribute 'return_date

any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:38:26+00:00Added an answer on June 17, 2026 at 6:38 am

    I wouldn’t have ‘total_days’ as a field in the LeaveRequest class, but rather as a property.

    class LeaveRequest(models.Model):
        (other fields)
    
        @property
        def total_days(self):
            oneday = datetime.timedelta(days=1)
            dt = self.start_date
            total_days = 0
            while(dt <= self.return_date):
                if not dt.isoweekday() in (6, 7):
                    total_days += 1
                dt += oneday
            return totaldays
    
    # view function
    def leave_screen(request, id):
        # get leave request by id
        leavereq = LeaveRequest.objects.get(id=id)
        return render_to_response("vacation/leave_request.html", {"leavereq": leavereq})
    
    # template code
    ...
    <body>
        {{ leavereq.total_days }}
    </body>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
I have a simple Observer that is watching certain models and writing the model
I have a simple model forms, that is being rendered through the following jinja2
In Java I use getters/setters when I have simple models/pojos. I find that the
I have a simple model like this: class User < ActiveRecord::Base serialize :preferences end
I have a simple model class (Part), which pulls from it's information from a
Suppose I have a simple model, such as Record: @Model public class Record {
in a django-tastypie app I have the following Django-models: class Car(models.Model): name=models.CharField('name',max_length=64) class CarTrack(models.Model):
I have a simple user model that stores an email address, crypted_password, salt and
I have a simple model, consisting of a document that references one or more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.