[Fixed]-Django: add item on admin site but it is not pubilished until I restart server

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.

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).

Leave a comment