我正在使用Django分页和jQuery。我可以序列化分页对象的对象列表,但我想序列化整个对象以获取更多数据(页码、总页数...)。 如何序列化整个分页对象?
谢谢
javascript
function getRestaurants(query) {
$.post("/getRestaurant/", query,
function(data) {
/* do stuff with data */
},"json" );
}
视图.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)