Fix cut and paste error from documentation

This is trying to build a pagination of a news queryset.

HT tmarble for pointing this out.
This commit is contained in:
Bradley M. Kuhn 2015-03-04 12:22:33 -08:00
parent 5c7710954b
commit 00995bff4d

View file

@ -19,25 +19,25 @@ class NewsListView(ListView):
return context return context
def listing(request): def listing(request):
news = PressRelease.objects.all() news_queryset = PressRelease.objects.all()
# if (not kwargs.has_key('allow_future')) or not kwargs['allow_future']: # if (not kwargs.has_key('allow_future')) or not kwargs['allow_future']:
news = news.filter(**{'%s__lte' % kwargs['date_field']: news_queryset = news_queryset.filter(**{'%s__lte' % kwargs['date_field']:
datetime.now()}) datetime.now()})
date_list = news.dates(kwargs['date_field'], 'year') date_list = news.dates(kwargs['date_field'], 'year')
paginator = Paginator(news, 6) # Show 6 news items per page paginator = Paginator(news_queryset, 6) # Show 6 news items per page
page = request.GET.get('page') page = request.GET.get('page')
try: try:
contacts = paginator.page(page) news = paginator.page(page)
except PageNotAnInteger: except PageNotAnInteger:
# If page is not an integer, deliver first page. # If page is not an integer, deliver first page.
contacts = paginator.page(1) news = paginator.page(1)
except EmptyPage: except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results. # If page is out of range (e.g. 9999), deliver last page of results.
contacts = paginator.page(paginator.num_pages) news = paginator.page(paginator.num_pages)
return render_to_response('pressrelease_list.html', {"news": news, "date_list" : date_list}) return render_to_response('pressrelease_list.html', {"news": news, "date_list" : date_list})