Following the example in
https://docs.djangoproject.com/en/4.1/topics/class-based-views/generic-display/#viewing-subsets-of-objects I tried the following
class BookListView(ListView):
model = Book
queryset = Book.objects.filter(publication_date__lte=timezone.now())
I found that this code snippet to retrieve only books that has the publication date before today (assuming that could be books with publication date in the future) not work as I would expected.
After some digging, I found that timezone.now() it's cached when server starts up (in a production environment), so this query filter by the date the server was started. So the solution is to use a dynamic filtering.
Could be a good idea to include some warning about this in the documentation?
Thanks,
Daniel