mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-25 19:14:01 +03:00
Add example to to_representation docs (#5682)
Closes #5425 as per https://github.com/encode/django-rest-framework/issues/5425#issuecomment-341063819
This commit is contained in:
parent
43c2c91dde
commit
b3a0b271cd
|
@ -1007,6 +1007,14 @@ The signatures for these methods are as follows:
|
|||
|
||||
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.
|
||||
|
||||
May be overridden in order modify the representation style. For example:
|
||||
|
||||
def to_representation(self, instance):
|
||||
"""Convert `username` to lowercase."""
|
||||
ret = super().to_representation(instance)
|
||||
ret['username'] = ret['username'].lower()
|
||||
return ret
|
||||
|
||||
#### ``.to_internal_value(self, data)``
|
||||
|
||||
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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user