mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-23 01:57:00 +03:00
add transform_<fieldname> methods to serializers, which basically do the opposite of validate_<fieldname> on a per-field basis.
This commit is contained in:
parent
f84d4951bf
commit
94cd136943
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user