1👍
I blogged about this issue here.
To summarize that post, although the queryset is indeed lazy and is only evaluated when the view is called, the definition of now
is not. As Tomita says, the answer is to define it in get_queryset
.
0👍
The behavior you describe is exactly what you should expect. You put your query in the class definition. It’s immediately evaluated and assigned to the variable queryset
.
Instead, override get_queryset
which is called every time..
def get_queryset(self):
return Message.objects.filter(message_type__id=1
).filter(inactive=False
).filter(start_time__range=(now, nextweek)
).order_by('-start_time', '-end_time')
Source:stackexchange.com