tabdon
tabdon

Reputation: 157

Problems Using Django Paginator with CouchDB

I'm trying to use Django's Paginator with CouchDB. The below code will successfully retrieve the docs/records from Couch. However, the problem is that it's returning all records; not the 5 per set that I want.

Am I making a mistake somewhere, or is Django's Paginator not compatible with Couch?

def content_queue(request):
# Get the current user
user = str(request.user)

# Filters the CouchDB View Doc "All" by user
couch_contents = ContentQueue.view("myapp/all", key=user)  

# This next section sets up Paginator
ITEMS_PER_PAGE = 5
paginator = Paginator(couch_contents, ITEMS_PER_PAGE)
try:
    page_number = int(request.GET['page'])
except (KeyError, ValueError):
    page_number = 1
try:
    page = paginator.page(page_number)
except InvalidPage:
    raise Http404

couch_contents = page.object_list

# Here I pass the variables to the template
variables = Context ({
    'couch_contents': couch_contents,
    'tag_list': tag_list,
    'show_paginator': paginator.num_pages > 1,
    'has_prev': page.has_previous(),
    'has_next': page.has_next(),
    'page': page_number,
    'pages': paginator.num_pages,
    'next_page': page_number + 1,
    'prev_page': page_number -1
})
return render_to_response('content_queue.html', variables)

Upvotes: 2

Views: 157

Answers (1)

LeafGlowPath
LeafGlowPath

Reputation: 3799

First, check what "page.object_list" really returns.

Then try converting couch_contents into a list before you pass it to Paginator.

Upvotes: 1

Related Questions