mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Docs tweaks
This commit is contained in:
parent
7ab4a587d9
commit
e7fd166048
|
@ -286,7 +286,7 @@ Would serialize to a nested representation like this:
|
|||
],
|
||||
}
|
||||
|
||||
# Writable nested serializers
|
||||
## Writable nested serializers
|
||||
|
||||
By default nested serializers are read-only. If you want to support write-operations to a nested serializer field you'll need to create `create()` and/or `update()` methods in order to explicitly specify how the child relationships should be saved.
|
||||
|
||||
|
@ -324,8 +324,14 @@ By default nested serializers are read-only. If you want to support write-operat
|
|||
>>> serializer.save()
|
||||
<Album: Album object>
|
||||
|
||||
---
|
||||
|
||||
# Custom relational fields
|
||||
|
||||
In rare cases where none of the existing relational styles fit the representation you need,
|
||||
you can implement a completely custom relational field, that describes exactly how the
|
||||
output representation should be generated from the model instance.
|
||||
|
||||
To implement a custom relational field, you should override `RelatedField`, and implement the `.to_representation(self, value)` method. This method takes the target of the field as the `value` argument, and should return the representation that should be used to serialize the target. The `value` argument will typically be a model instance.
|
||||
|
||||
If you want to implement a read-write relational field, you must also implement the `.to_internal_value(self, data)` method.
|
||||
|
|
Loading…
Reference in New Issue
Block a user