You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api-guide/serializers.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1007,6 +1007,14 @@ The signatures for these methods are as follows:
1007
1007
1008
1008
Takes the object instance that requires serialization, and should return a primitive representation. Typically this means returning a structure of built-in Python datatypes. The exact types that can be handled will depend on the render classes you have configured for your API.
1009
1009
1010
+
May be overridden in order modify the representation style. For example:
1011
+
1012
+
def to_representation(self, instance):
1013
+
"""Convert `username` to lowercase."""
1014
+
ret = super().to_representation(instance)
1015
+
ret['username'] = ret['username'].lower()
1016
+
return ret
1017
+
1010
1018
#### ``.to_internal_value(self, data)``
1011
1019
1012
1020
Takes the unvalidated incoming data as input and should return the validated data that will be made available as `serializer.validated_data`. The return value will also be passed to the `.create()` or `.update()` methods if `.save()` is called on the serializer class.
0 commit comments