tomchristie/django-rest-framework — pull request #358 by jmagnusson (2012-11-02 20:52:50+00:00)
Title: Return dictionaries as is

Okay so I've got the following model:

class Model(models.Model):
@property
def props(self):
return {
'foo': 'bar',
'foo_bar': {
'f': 1,
'o': 2,
},
}

class Serializer(serializers.ModelSerializer):
props = serializers.Field(source='props')

class Meta:
fields = ('props', )

What `fields.Field.to_native` currently does is to return a string representation of the dictionary like this: `"{'foo_bar': {'foo': 1, 'bar': 2}, 'foo': 'bar'}"`. I've changed the default to what I think is a more sensible behavior, returning dictionaries as is (it recursively applies to_native on keys and values of the dict like is currently done with values of other iterables).