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

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -