I have a Django model that contains a date field:
class Event(models.Model):
event_date = models.DateField()
I’d like to have a manager on this model that shows only the events that occurred within a time period defined as July 1 (CURRENT YEAR) to June 31 (FOLLOWING YEAR).
So for this year, I’d want to return events beginning July 1, 2011 to June 31, 2012. And when the current date hits July 1, 2012, we’d show events happening to June 31, 2013.
How would I go about doing this?
Thanks!
Straight from the docs:
https://docs.djangoproject.com/en/dev/ref/models/querysets/#range
So the only challenge is figuring out what the current year is and adjusting the start and end date to reflect that. One manager approach:
now you can query: