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

  • SEARCH
  • Home
  • 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 6756239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:30:03+00:00 2026-05-26T13:30:03+00:00

I have a Django model for an object with a DateField. I also have

  • 0

I have a Django model for an object with a DateField. I also have two managers that filter these objects for a specific date range.

class SchoolYearManager(models.Manager):
    def get_query_set(self):
        now = datetime.datetime.now()
        current_year = now.year
        start_date = datetime.date(current_year, 7, 1)
        end_date = datetime.date((current_year + 1), 6, 30)
        return super(SchoolYearManager, self).get_query_set().filter(status=self.model.LIVE).filter(event_date__range=(start_date, end_date))

class PastSchoolYearManager(models.Manager):
    def get_query_set(self):
        current_year = self.model.event_date.year
        start_date = datetime.date(current_year, 7, 1)
        end_date = datetime.date((current_year + 1), 6, 30)
        return super(PastSchoolYearManager, self).get_query_set().filter(status=self.model.LIVE).filter(event_date__range=(start_date, end_date))

class Event(models.Model):
    LIVE = 3
    DRAFT = 4
    STATUS_CHOICES = (
        (LIVE, 'Live'),
        (DRAFT, 'Draft'),
    )
    status = models.IntegerField(choices=STATUS_CHOICES, default=4, help_text="Only entries with a status of 'live' will be displayed publically.")
    event_date = models.DateField()

    objects = Models.Manager()
    school_year_events = SchoolYearManager()
    past_school_year_events = PastSchoolYearManager()

My first manager (SchoolYearManager) works as expected to return events within that date range. But when I try to do Event.past_school_year_events.all(), I get an Attribute error: “type object ‘Event’ has no attribute ‘event_date'”.

My goal with the second manager (PastSchoolYearEvents) is to wrap a generic year archive view to return events within a date range for a specific year.

Why can’t I call self.model.event_date within the manager?

Am I going about this the right way? If not, what’s the better way to do this?

  • 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-05-26T13:30:04+00:00Added an answer on May 26, 2026 at 1:30 pm

    How could this work? What event date could it be referring to? When you call Event.past_school_year_events.all(), you don’t have a model instance. self.model, as the name implies, refers to the model class. So how could it know what date you mean?

    I can’t actually work out what it is you’re trying to do – where you are going to get the date from. Do you want to start from an event, then get all the other events in the same year as that one? In which case, I suspect you just want to make past_school_year_events into a model method, not a manager.

    Edit If you want to start from a specific year, a manager certainly is appropriate, but you’ll need to pass the year into your manager method as a parameter. For this, I’d use a separate method on the manager, rather than overriding get_query_set – in fact, add another method to SchoolYearManager:

    class SchoolYearManager(models.Manager):
        def live_events(self, start_date, end_date):
           return self.filter(status=self.model.LIVE).filter(event_date__range=(start_date, end_date))
    
        def this_year(self):
            now = datetime.datetime.now()
            current_year = now.year
            start_date = datetime.date(current_year, 7, 1)
            end_date = datetime.date((current_year + 1), 6, 30)
            return self.live_events(start_date, end_date)
    
        def from_year(self, year):
            start_date = datetime.date(year, 7, 1)
            end_date = datetime.date(year+1, 6, 30)
            return self.live_events(start_date, end_date)
    

    Now you’ve got just one manager, that doesn’t override get_query_set, so you don’t even need to preserve the default one – you can keep this one as objects. So you can do:

    Event.objects.this_year()  # all this year's events
    Event.objects.from_year(2010) # all events from 2010
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have django objects: class Event(models.Model): title = models.CharField(max_length=255) event_start_date = models.DateField(null=True, blank='true') ...
I have two Django model classes that are structured similar to the following: class
I have a Django model TimeThingie with two TimeField s called t1 and t2
I want to generate a list using my django model say I have these
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
I have a Django form that uses an integer field to lookup a model
I have the following Django model: created=models.DateTimeField(auto_now_add=True) I now need a model object method
I have a Django model (schedule) with the class of entity, that is the
I have a Django project whereby every model inherits from a common Object model
Lets say I have some Django model that has a list of numbers as

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.