Skip to content

Commit b3a0b27

Browse files
Add example to to_representation docs (#5682)
Closes #5425 as per #5425 (comment)
1 parent 43c2c91 commit b3a0b27

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

docs/api-guide/serializers.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,14 @@ The signatures for these methods are as follows:
10071007

10081008
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.
10091009

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+
10101018
#### ``.to_internal_value(self, data)``
10111019

10121020
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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy