aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Christie2014-10-16 20:45:36 +0100
committerTom Christie2014-10-16 20:47:57 +0100
commit32fd82ba0d6082418e5ca5633f9e9709bd44e86b (patch)
treed24903befa7f9115dd3b749a02e94022058c8051
parent7b666e982c461e237567435851dcc93bc76581e5 (diff)
downloaddjango-rest-framework-32fd82ba0d6082418e5ca5633f9e9709bd44e86b.tar.bz2
get_attribute method on fields
-rw-r--r--rest_framework/fields.py9
-rw-r--r--rest_framework/serializers.py6
2 files changed, 8 insertions, 7 deletions
diff --git a/rest_framework/fields.py b/rest_framework/fields.py
index 24dfaaf5..597d5e12 100644
--- a/rest_framework/fields.py
+++ b/rest_framework/fields.py
@@ -212,15 +212,12 @@ class Field(object):
return self.default_empty_html if (ret == '') else ret
return dictionary.get(self.field_name, empty)
- def get_field_representation(self, instance):
+ def get_attribute(self, instance):
"""
- Given the outgoing object instance, return the primitive value
+ Given the *outgoing* object instance, return the primitive value
that should be used for this field.
"""
- attribute = get_attribute(instance, self.source_attrs)
- if attribute is None:
- return None
- return self.to_representation(attribute)
+ return get_attribute(instance, self.source_attrs)
def get_default(self):
"""
diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py
index f72ecb0b..30e6bfeb 100644
--- a/rest_framework/serializers.py
+++ b/rest_framework/serializers.py
@@ -379,7 +379,11 @@ class Serializer(BaseSerializer):
fields = [field for field in self.fields.values() if not field.write_only]
for field in fields:
- value = field.get_field_representation(instance)
+ attribute = field.get_attribute(instance)
+ if attribute is None:
+ value = None
+ else:
+ value = field.to_representation(attribute)
transform_method = getattr(self, 'transform_' + field.field_name, None)
if transform_method is not None:
value = transform_method(value)