4👍
✅
You can make a query like this by specifying the day and the month:
def on_this_day(day, month):
return Event.objects.filter(date__day=day, date__month=month)
It most likely scans your database table using SQL operators like MONTH(date)
and DAY(date)
or some lookup equivalent
You might get a better query performance if you add and index Event.day
and Event.month
(if Event.date
is internally stored as an int
in the DB, it makes it less adapted to your (day, month)
queries)
Here’s some docs from Django: https://docs.djangoproject.com/en/dev/ref/models/querysets/#month
Source:stackexchange.com