serialize queryset via django-rest-framework -
i try use updating version of drf. used code tutorial
serializer = snippetserializer(snippet.objects.all(), many=true) serializer.data
i should
[{ 'pk': 1, 'title': u'', 'code': u'foo = "bar"\n', 'linenos': false, 'language': u'python', 'style': u'friendly' }, { 'pk': 2, 'title': u'', 'code': u'print "hello, world"\n', 'linenos': false, 'language': u'python', 'style': u'friendly' }]
but got:
[ordereddict([ ('pk', 1), ('title', u''), ('code', u'foo = "bar"\n'), ('linenos', false), ('language', 'python'), ('style', 'friendly') ]), ordereddict([ ('pk', 2), ('title', u''), ('code', u'print "hello, world"\n'), ('linenos', false), ('language', 'python'), ('style', 'friendly') ]) ]
please explain how correctly results?
if need valid json, can
import json serializer = snippetserializer(snippet.objects.all(), many=true) json.dumps(serializer.data)
Comments
Post a Comment