Here is scenario:
I want to publish one item per day. Sometimes I will add more than one item and set them on different pub_date
on admin site. By setting queryset like this item.objects.exclude(pub_date__gt=timezone.now().date())
, this will prevent the items on future publish date from publishing. However, I do not get my expected result. P.S. I get my expected result on python manage.py shell
and if restart my server--gunicorn manually, the items are published.
Maybe it is related to my server Upstart script, here it is,
start on runlevel [2345]
stop on runlevel [!2345]
respawn
setuid myid
setgid www-data
chdir /home/myid/my_repo_dir/my_proj_dir
exec /home/myid/.virtualenvs/my_proj_env/bin/gunicorn --workers 3 --bind unix:/home/my_id/my_repo_dir/my_proj_dir/project.sock config.wsgi:application$
Here is the view:
class HomeView(ListView):
queryset = Item.objects.exclude(pub_date__gt=timezone.now().date())
template_name = 'home.html'
context_object_name = 'items'
What I cannot understand is that the same code in view and in python manage.py shell
produces different results.