2👍
✅
If you’re going to use a function call for the queryset filter, you can’t set it as an attribute. You must override get_queryset
.
def get_queryset(self):
queryset = super(PostListView, self).get_queryset()
return queryset.filter(is_active=True, created__lt=timezone.now())
The reason is because timezone.now() will always return the value of when the class was first compiled. You might be able to get away with using .filter(created__lt=timezone.now)
but I haven’t tried that.
Source:stackexchange.com