Hey everyone,
I have the following:
[snip]
def people_json(request):
userobjects = User.objects.filter(is_superuser=False).extra(order_by
= ['auth_user.username+0'])
p = Paginator(userobjects, 10)
pagenumber = request.POST.get('pagenumber', 1)
try:
users = p.page(pagenumber)
except:
users = p.page(1)
json_serializer = serializers.get_serializer("json")()
data = json_serializer.serialize(users.object_list,
ensure_ascii=False, fields=('username', 'first_name', 'last_name',
'email'))
return HttpResponse(data, mimetype='application/javascript')
[/snip]
This will return a JSON string to the browser that I use to make a
people overview that uses AJAX.
Anyway, because I have to draw 'previous' and 'next' buttons, I want
to attach some extra data to the json response.
For example I would like to concatenate the following list to the
response:
pageinfo = [p.start_index(), p.end_index(), p.paginator.count,
p.has_next(), p.has_previous()]
I tried to convert users.object_list to a list and concatenate it with
pageinfo, but that doesn't work ( tells me str doesn't have the
attribute _meta ).
I don't want to use html as a response because that would throw more
bytes over the pipe. ( it's also slower ).
I also don't want to use 2 separate requests because that would be
more overhead ( 2 separate requests take more time and it would also
result in to 2 queries because the Paginator has to be initiated once
again ).
Does anyone have a good solution for this problem? Using Django has
been a great experience but things like this take a looooot of time.
Thanks!
Henk.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---