On Sunday, 3 November 2013 18:09:49 UTC, Leon Sasson wrote:
> Django serializer works really well when you need to serialize a QuerySet,
> but often times I need to serialize a JSON object with more than just a
> QuerySet.
> This leads me to serialize the QuerySet, and then load it again to a
> python dict and then serialize it again. Like this:
>
> peopleJSON = serializers.serialize("json", people_queryset)
> people_dict = simplejson.loads(peopleJSON )
> json = simplejson.dumps({'foo': foo, 'people':people_dict})
>
> A better way would be:
> data = {'foo':foo, 'people':people_queryset}
> json = serializers.serialize("json", data)
>
> Is there a reason not to allow this behavior? I can't think of one.
>
You can pretty much get what you want already by using the `python`
serializer and then dumping the whole load to JSON:
qs = serializers.serialize("python", people_queryset)
json = simplejson.dumps({"foo": foo, "people": qs})
--
DR.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/38942ffc-b198-4065-b3b7-4ffef8585ba2%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.