From 2946251c918f31801cea756171cb5ea153704f6c Mon Sep 17 00:00:00 2001 From: koliber Date: Tue, 18 Aug 2015 14:47:04 +0200 Subject: [PATCH 1/2] Added explicit id field in multi update example If the id field is implicitly created, it is created as `read_only=True`. This causes the data validation step to remove the id values in the validated data. --- docs/api-guide/serializers.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md index abdb67afa..d0b6a3c5b 100644 --- a/docs/api-guide/serializers.md +++ b/docs/api-guide/serializers.md @@ -774,6 +774,11 @@ Here's an example of how you might choose to implement multiple updates: class BookSerializer(serializers.Serializer): ... + id = serializers.IntegerField( + read_only=False, + required=False + ) + class Meta: list_serializer_class = BookListSerializer From dae5426e20eb8b6f215344d2a868c4ff31af3f99 Mon Sep 17 00:00:00 2001 From: koliber Date: Fri, 28 Aug 2015 15:35:32 +0200 Subject: [PATCH 2/2] Changed formatting and updated docs --- docs/api-guide/serializers.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md index d0b6a3c5b..66f3c4d43 100644 --- a/docs/api-guide/serializers.md +++ b/docs/api-guide/serializers.md @@ -747,6 +747,8 @@ To support multiple updates you'll need to do so explicitly. When writing your m * How should insertions be handled? Are they invalid, or do they create new objects? * How should removals be handled? Do they imply object deletion, or removing a relationship? Should they be silently ignored, or are they invalid? * How should ordering be handled? Does changing the position of two items imply any state change or is it ignored? + +You will need to add an explicit `id` field to the instance serializer. The default implicitly-generated `id` field is marked as `read_only`. This causes it to be removed on updates. Once you declare it explicitly, it will be available in the list serializer's `update` method. Here's an example of how you might choose to implement multiple updates: @@ -774,10 +776,7 @@ Here's an example of how you might choose to implement multiple updates: class BookSerializer(serializers.Serializer): ... - id = serializers.IntegerField( - read_only=False, - required=False - ) + id = serializers.IntegerField(required=False) class Meta: list_serializer_class = BookListSerializer