Any way to serialize a pagination object in Django?

353 views
Skip to first unread message

jul

unread,
Dec 11, 2009, 8:20:55 AM12/11/09
to Django users
hi,

I'm using Django pagination with jQuery. I can serialize the objects
list of the pagination object, but I'd like to serialize the whole
object to get more data (page number, total number of pages...). How
can I serialize the whole pagination object?

Thanks

***javascript***

function getRestaurants(query) {

$.post("/getRestaurant/", query,
function(data) {
/* do stuff with data */
},"json" );
}

***views.py***

def getRestaurant(request):

results = Restaurant.objects.all()
paginator = Paginator(restaurants, 5)

# Make sure page request is an int. If not, deliver first page.
try:
page = int(request.POST.get('page','1'))
except ValueError:
page = 1

# If page request (9999) is out of range, deliver last page of
results.
try:
results = paginator.page(page)
except (EmptyPage, InvalidPage):
results = paginator.page(paginator.num_pages)

data=serializers.serialize("json", results.object_list) #I'd like
to serialize the whole results object

return HttpResponse(data)

Reply all
Reply to author
Forward
0 new messages