Question about django.core.serializers

0 views
Skip to first unread message

ska...@gmail.com

unread,
Jul 6, 2006, 12:01:46 PM7/6/06
to Django developers
I was very excited to hear about the new json serializer code that has
been added into Django. While going over it I found myself wondering
why I could only serialize a queryset and not just a single object.

Is there a reason why I am not allowed to serialize
MyObject.objects.get(pk=1)?

Jacob Kaplan-Moss

unread,
Jul 6, 2006, 12:07:46 PM7/6/06
to django-d...@googlegroups.com
On Jul 6, 2006, at 11:01 AM, ska...@gmail.com wrote:
> I was very excited to hear about the new json serializer code that has
> been added into Django. While going over it I found myself wondering
> why I could only serialize a queryset and not just a single object.

You can serialize any iterable, so just do:

serializers.serialize("xml", [object])

Why? Consistency; it turned out to be a pain to always have to check
weather serialized data was a list of objects or a single object.
It's easier to just always deal with lists (since that's the common
case anyway).

Jacob

Reply all
Reply to author
Forward
0 new messages