How do I filter query objects by date range in Django?
Or if you are just trying to filter month wise:
As Bernhard Vallant said, if you want a queryset which excludes the
specified range ends you should consider his solution, which utilizes gt/lt (greater-than/less-than).
When doing django ranges with a filter make sure you know the difference between using a date object vs a datetime object. __range is inclusive on dates but if you use a datetime object for the end date it will not include the entries for that day if the time is not set.
from datetime import date, timedeltastartdate = date.today()enddate = startdate + timedelta(days=6)Sample.objects.filter(date__range=[startdate, enddate])
returns all entries from startdate to enddate including entries on those dates. Bad example since this is returning entries a week into the future, but you get the drift.
from datetime import datetime, timedeltastartdate = datetime.today()enddate = startdate + timedelta(days=6)Sample.objects.filter(date__range=[startdate, enddate])
will be missing 24 hours worth of entries depending on what the time for the date fields is set to.