That would definitely work.
I guess it's missing from the
docs<https://docs.djangoproject.com/en/1.6/topics/serialization/#serialization-formats>—
only 'xml', 'json', and 'yaml' formats are documented. The 'python'
serialization format was documented until version 1.1, but then removed,
although it is still
implemented<https://github.com/django/django/blob/stable/1.6.x/django/core/serializers/__init__.py#L27>
as
of 1.6.
On Sunday, November 3, 2013 3:11:14 PM UTC-5, Daniel Roseman wrote:
>
> 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/b378fc41-1626-4ef6-b97a-cec6cd47d6f4%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.