aboutsummaryrefslogtreecommitdiffstats
path: root/docs/topics/writable-nested-serializers.md
diff options
context:
space:
mode:
authorPhilip Douglas2013-09-13 10:47:06 +0100
committerPhilip Douglas2013-09-13 10:47:06 +0100
commite5da0ff5e530c8ea0e2cf4dff0723ede6234860e (patch)
tree776ec2dd47b6c8a4aa976d33c740d4b0267c9522 /docs/topics/writable-nested-serializers.md
parent272a6abf91c51b44781d27af5352c7e36c8fa91c (diff)
parentea462b7b9b28f425c8c91d10e34532ddbb3c87fa (diff)
downloaddjango-rest-framework-e5da0ff5e530c8ea0e2cf4dff0723ede6234860e.tar.bz2
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'docs/topics/writable-nested-serializers.md')
-rw-r--r--docs/topics/writable-nested-serializers.md47
1 files changed, 47 insertions, 0 deletions
diff --git a/docs/topics/writable-nested-serializers.md b/docs/topics/writable-nested-serializers.md
new file mode 100644
index 00000000..66ea7815
--- /dev/null
+++ b/docs/topics/writable-nested-serializers.md
@@ -0,0 +1,47 @@
+> To save HTTP requests, it may be convenient to send related documents along with the request.
+>
+> — [JSON API specification for Ember Data][cite].
+
+# Writable nested serializers
+
+Although flat data structures serve to properly delineate between the individual entities in your service, there are cases where it may be more appropriate or convenient to use nested data structures.
+
+Nested data structures are easy enough to work with if they're read-only - simply nest your serializer classes and you're good to go. However, there are a few more subtleties to using writable nested serializers, due to the dependancies between the various model instances, and the need to save or delete multiple instances in a single action.
+
+## One-to-many data structures
+
+*Example of a **read-only** nested serializer. Nothing complex to worry about here.*
+
+ class ToDoItemSerializer(serializers.ModelSerializer):
+ class Meta:
+ model = ToDoItem
+ fields = ('text', 'is_completed')
+
+ class ToDoListSerializer(serializers.ModelSerializer):
+ items = ToDoItemSerializer(many=True, read_only=True)
+
+ class Meta:
+ model = ToDoList
+ fields = ('title', 'items')
+
+Some example output from our serializer.
+
+ {
+ 'title': 'Leaving party preperations',
+ 'items': {
+ {'text': 'Compile playlist', 'is_completed': True},
+ {'text': 'Send invites', 'is_completed': False},
+ {'text': 'Clean house', 'is_completed': False}
+ }
+ }
+
+Let's take a look at updating our nested one-to-many data structure.
+
+### Validation errors
+
+### Adding and removing items
+
+### Making PATCH requests
+
+
+[cite]: http://jsonapi.org/format/#url-based-json-api \ No newline at end of file