add transform_<fieldname> methods to serializers, which basically do the opposite of validate_<fieldname> on a per-field basis.

This commit is contained in:
Craig de Stigter 2013-08-29 17:35:15 +12:00
parent f84d4951bf
commit 94cd136943

View File

@ -304,6 +304,9 @@ class BaseSerializer(WritableField):
field.initialize(parent=self, field_name=field_name)
key = self.get_field_key(field_name)
value = field.field_to_native(obj, field_name)
method = getattr(self, 'transform_%s' % field_name, None)
if callable(method):
value = method(obj, value)
ret[key] = value
ret.fields[key] = field
return ret