Commit 60901446 by Tom Christie

Simplify serialization slightly

parent 8be44965
......@@ -202,12 +202,15 @@ class Field(object):
return self.default_empty_html if (ret == '') else ret
return dictionary.get(self.field_name, empty)
def get_attribute(self, instance):
def get_field_representation(self, instance):
"""
Given the *outgoing* object instance, return the value for this field
that should be returned as a primative value.
Given the outgoing object instance, return the primative value
that should be used for this field.
"""
return get_attribute(instance, self.source_attrs)
attribute = get_attribute(instance, self.source_attrs)
if attribute is None:
return None
return self.to_representation(attribute)
def get_default(self):
"""
......
......@@ -268,8 +268,7 @@ class Serializer(BaseSerializer):
fields = [field for field in self.fields.values() if not field.write_only]
for field in fields:
native_value = field.get_attribute(instance)
ret[field.field_name] = field.to_representation(native_value)
ret[field.field_name] = field.get_field_representation(instance)
return ret
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment