Avoid PostTracking.DoesNotExist exception when no Posts exist.

This happens on a fresh install when a users clicks on "Show new posts
since last visit".
This commit is contained in:
Andi Albrecht 2012-04-02 13:59:35 +02:00
parent 2acc7b1ee9
commit 1d2eb6ce38

View file

@ -118,7 +118,10 @@ def search(request):
date = datetime.today() - timedelta(1)
topics = topics.filter(created__gte=date)
elif action == 'show_new':
last_read = PostTracking.objects.get(user=request.user).last_read
try:
last_read = PostTracking.objects.get(user=request.user).last_read
except PostTracking.DoesNotExist:
last_read = None
if last_read:
topics = topics.filter(last_post__updated__gte=last_read).all()
else: