On 12/18/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> I use a generic detail view to show user info. I want to also be able
> to return that info via ajax, but I'm having trouble getting ALL the
> user stuff. Here's the view:
>
> def view_profile(request, slug, js=''):
>     from django.views.generic.list_detail import object_detail
>     auth_user = User.objects.get(username=slug)
>     user_id = auth_user.id
>     username = auth_user.username
>     gpuser = GpUser.objects.get(user=user_id)
>     lastseen= request.session['last_seen']
>
>     if js== 'js':
>         return HttpResponse(simplejson.dumps(gpuser.preferred_name,),
> mimetype='application/javascript')
>     return object_detail(
>         request,
>         queryset=GpUser.objects.all(),
>         extra_context={'lastseen': lastseen},
>         template_object_name='gpuser',
>         object_id=gpuser.id,
>         template_name="users/user_detail.html",
>     )
> The generic view is good, and I can return single things, like
> preferred_name, but how do I get all the gpuser objects?
>

The serializer stuff, which for json is built on simplejson, can do the trick.

from django.core import serializers
json = serializers.serialize('json', GpUser.objects.all())

See http://www.djangoproject.com/documentation/serialization/ for more info.

Cheers,
deryck

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to