def campaign_detail(request, pk):
''' Renders a template showing the photo results of the campaign. 20 results per page,
with pagination capabilities at the bottom of each page.'''
campaign = get_object_or_404(Campaign, pk=pk)
# Query the DB to find all Photo records associated with this campaign
results = Photo.objects.filter(campaign_number=pk)
# Set up the pagination of the results
paginator = Paginator(results, 20) # Show 20 contacts per page
page = request.GET.get('page')
try:
page_content = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
page_content = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
page_content = paginator.page(paginator.num_pages)
return render(request, 'ig_miner_app/campaign_detail.html', {'campaign': campaign,
'results':results,
'page_content': page_content})
评论列表
文章目录