mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-02 20:54:42 +03:00
Simplify serialization slightly
This commit is contained in:
parent
8be4496586
commit
6090144608
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user