1👍
Override get_queryset
, so that the queryset is evaluated each time the view runs.
class HomeView(ListView):
def get_queryset(self) :
return Item.objects.exclude(pub_date__gt=timezone.now().date())
Currently, you have set queryset
. This causes the queryset to be fetched once when the server starts and the view is loaded. It does not change until the server is restarted.
0👍
I suggest you switch from using upstart to gunicorn+supervisor that way it’s easier for you to restart your django applications. Also it’ll be helpful if you could add more snippets as to how you implemented your queryset.
- Use django admin to save a list of selected objects to another table
- How get individual fields from django model?
- How to implement the official django polls example equivalently by using forms?
- Making the first image select by default as featured from the modelformset_factory
- Django – passing extra arguments into default callable function
0👍
In certain situations (specifically ModelField default values), the .now().date() is evaluated at server start, not at time of calling the method. In that situation, you remove the parenthesis.
This would explain why it works in your shell (because your shell is always todays date).
Try removing the parenthesis from item.objects.exclude(pub_date__gt=timezone.now().date())
to make it item.objects.exclude(pub_date__gt=timezone.now.date)
.
- Django – Use forloop.counter0
- Django messages framework
- Restrict access to view based on if request came from other view