Commit 94cd1369 by Craig de Stigter

add transform_<fieldname> methods to serializers, which basically do the…

add transform_<fieldname> methods to serializers, which basically do the opposite of validate_<fieldname> on a per-field basis.
parent f84d4951
......@@ -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
......
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