mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 19:40:13 +03:00
Add note about testing writable nested serializers
This commit is contained in:
parent
d2994e0596
commit
434f243f7c
|
@ -290,6 +290,8 @@ Would serialize to a nested representation like this:
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
|
Note that django-rest-framework's [MultiPartRenderer] doesn't handle writing nested data properly, so if you're going to be testing this functionality, you'll need to add `format='json'` to your test requests.
|
||||||
|
|
||||||
class TrackSerializer(serializers.ModelSerializer):
|
class TrackSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Track
|
model = Track
|
||||||
|
@ -598,3 +600,4 @@ The [rest-framework-generic-relations][drf-nested-relations] library provides re
|
||||||
[generic-relations]: https://docs.djangoproject.com/en/stable/ref/contrib/contenttypes/#id1
|
[generic-relations]: https://docs.djangoproject.com/en/stable/ref/contrib/contenttypes/#id1
|
||||||
[drf-nested-routers]: https://github.com/alanjds/drf-nested-routers
|
[drf-nested-routers]: https://github.com/alanjds/drf-nested-routers
|
||||||
[drf-nested-relations]: https://github.com/Ian-Foote/rest-framework-generic-relations
|
[drf-nested-relations]: https://github.com/Ian-Foote/rest-framework-generic-relations
|
||||||
|
[MultiPartRenderer]: http://www.django-rest-framework.org/api-guide/renderers/#multipartrenderer
|
||||||
|
|
Loading…
Reference in New Issue
Block a user