So, I know I can use __lte and __gte filters on object dates using the Django ORM as so:
events = Event.objects.all().order_by('start_date').filter(
start_date__lte=_day, end_date__gte=_day
)
I can also query against date components:
events = Event.objects.all().order_by('start_date').filter(
start_date__day=_day.day, end_date__day=_day.day
)
but what I’m trying to figure out is can I query against specific parts of the date AND also use the gte and lte operators, such as the following attempt that doesn’t work:
events = Event.objects.all().order_by('start_date').filter(
start_date__day__lte=8, end_date__day__gte=_day
)
Short answer: no, you can’t.
Long(er) answer:
In this case I’d create a method on the manager, and use either
.extra(where='...')(which would probably require DB-specific SQL code) or a combination ofmodels.Qobjects on theEventqueryset.Edited: the
wherearg had to be a sequence.