Docs tweaks

This commit is contained in:
Tom Christie 2016-09-29 21:29:21 +01:00
parent 7ab4a587d9
commit e7fd166048

View File

@ -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. 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() >>> serializer.save()
<Album: Album object> <Album: Album object>
---
# Custom relational fields # 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. 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. If you want to implement a read-write relational field, you must also implement the `.to_internal_value(self, data)` method.