diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/topics/3.0-announcement.md | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/docs/topics/3.0-announcement.md b/docs/topics/3.0-announcement.md index fcae79e1..4a781503 100644 --- a/docs/topics/3.0-announcement.md +++ b/docs/topics/3.0-announcement.md @@ -109,16 +109,16 @@ The following example from the tutorial previously used `restore_object()` to ha This would now be split out into two separate methods. - def update(self, instance, validated_attrs) - instance.title = validated_attrs.get('title', instance.title) - instance.code = validated_attrs.get('code', instance.code) - instance.linenos = validated_attrs.get('linenos', instance.linenos) - instance.language = validated_attrs.get('language', instance.language) - instance.style = validated_attrs.get('style', instance.style) + def update(self, instance, validated_data) + instance.title = validated_data.get('title', instance.title) + instance.code = validated_data.get('code', instance.code) + instance.linenos = validated_data.get('linenos', instance.linenos) + instance.language = validated_data.get('language', instance.language) + instance.style = validated_data.get('style', instance.style) instance.save() - def create(self, validated_attrs): - return Snippet.objects.create(**validated_attrs) + def create(self, validated_data): + return Snippet.objects.create(**validated_data) Note that the `.create` method should return the newly created object instance. @@ -134,15 +134,14 @@ For example the following code *is no longer valid*: serializer.object.user = request.user # Include the user when saving. serializer.save() -Instead of using `.object` to inspect a partially constructed instance, you would now use `.validated_data` to inspect the cleaned incoming values. Also you can't set extra attributes on the instance directly, but instead pass them to the `.save()` method using the `extras` keyword argument. +Instead of using `.object` to inspect a partially constructed instance, you would now use `.validated_data` to inspect the cleaned incoming values. Also you can't set extra attributes on the instance directly, but instead pass them to the `.save()` method as keyword arguments. The corresponding code would now look like this: if serializer.is_valid(): name = serializer.validated_data['name'] # Inspect validated field data. logging.info('Creating ticket "%s"' % name) - extras = {'user': request.user} # Include the user when saving. - serializer.save(extras=extras) + serializer.save(user=request.user) # Include the user when saving. #### Limitations of ModelSerializer validation. |
