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)