Add note about testing writable nested serializers

This commit is contained in:
Nik Nyby 2018-03-02 15:46:23 -05:00 committed by GitHub
parent d2994e0596
commit 434f243f7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.
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 Meta:
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
[drf-nested-routers]: https://github.com/alanjds/drf-nested-routers
[drf-nested-relations]: https://github.com/Ian-Foote/rest-framework-generic-relations
[MultiPartRenderer]: http://www.django-rest-framework.org/api-guide/renderers/#multipartrenderer