I try to use updating version of DRF. I used code from tutorial
serializer = SnippetSerializer(Snippet.objects.all(), many=True)
serializer.data
I should get
[{
'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 I 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 get correctly results?
OrderedDictis from python'scollectionsmodule (docs.python.org/3/library/collections.html).OrderedDictto adictby callingdict(serializer.data), but then you lose any field ordering.ValueError: dictionary update sequence element #0 has length 6; 2 is required