You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/topics/3.0-announcement.md
+11-11Lines changed: 11 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -189,13 +189,13 @@ You can either return `non_field_errors` from the validate method by raising a s
189
189
190
190
def validate(self, attrs):
191
191
# serializer.errors == {'non_field_errors': ['A non field error']}
192
-
raise serailizers.ValidationError('A non field error')
192
+
raise serializers.ValidationError('A non field error')
193
193
194
194
Alternatively if you want the errors to be against a specific field, use a dictionary of when instantiating the `ValidationError`, like so:
195
195
196
196
def validate(self, attrs):
197
197
# serializer.errors == {'my_field': ['A field error']}
198
-
raise serailizers.ValidationError({'my_field': 'A field error'})
198
+
raise serializers.ValidationError({'my_field': 'A field error'})
199
199
200
200
This ensures you can still write validation that compares all the input fields, but that marks the error against a particular field.
201
201
@@ -303,7 +303,7 @@ Alternatively, specify the field explicitly on the serializer class:
303
303
model = MyModel
304
304
fields = ('id', 'email', 'notes', 'is_admin')
305
305
306
-
The `read_only_fields` option remains as a convenient shortcut for the more common case.
306
+
The `read_only_fields` option remains as a convenient shortcut for the more common case.
307
307
308
308
#### Changes to `HyperlinkedModelSerializer`.
309
309
@@ -364,7 +364,7 @@ The `ListSerializer` class has now been added, and allows you to create base ser
364
364
class MultipleUserSerializer(ListSerializer):
365
365
child = UserSerializer()
366
366
367
-
You can also still use the `many=True` argument to serializer classes. It's worth noting that `many=True` argument transparently creates a `ListSerializer` instance, allowing the validation logic for list and non-list data to be cleanly separated in the REST framework codebase.
367
+
You can also still use the `many=True` argument to serializer classes. It's worth noting that `many=True` argument transparently creates a `ListSerializer` instance, allowing the validation logic for list and non-list data to be cleanly separated in the REST framework codebase.
368
368
369
369
You will typically want to *continue to use the existing `many=True` flag* rather than declaring `ListSerializer` classes explicitly, but declaring the classes explicitly can be useful if you need to write custom `create` or `update` methods for bulk updates, or provide for other custom behavior.
370
370
@@ -436,7 +436,7 @@ Here's a complete example of our previous `HighScoreSerializer`, that's been upd
436
436
def to_internal_value(self, data):
437
437
score = data.get('score')
438
438
player_name = data.get('player_name')
439
-
439
+
440
440
# Perform the data validation.
441
441
if not score:
442
442
raise ValidationError({
@@ -450,7 +450,7 @@ Here's a complete example of our previous `HighScoreSerializer`, that's been upd
450
450
raise ValidationError({
451
451
'player_name': 'May not be more than 10 characters.'
452
452
})
453
-
453
+
454
454
# Return the validated values. This will be available as
455
455
# the `.validated_data` property.
456
456
return {
@@ -463,15 +463,15 @@ Here's a complete example of our previous `HighScoreSerializer`, that's been upd
463
463
'score': obj.score,
464
464
'player_name': obj.player_name
465
465
}
466
-
466
+
467
467
def create(self, validated_data):
468
468
return HighScore.objects.create(**validated_data)
469
469
470
470
#### Creating new generic serializers with `BaseSerializer`.
471
471
472
472
The `BaseSerializer` class is also useful if you want to implement new generic serializer classes for dealing with particular serialization styles, or for integrating with alternative storage backends.
473
473
474
-
The following class is an example of a generic serializer that can handle coercing aribitrary objects into primitive representations.
474
+
The following class is an example of a generic serializer that can handle coercing aribitrary objects into primitive representations.
475
475
476
476
class ObjectSerializer(serializers.BaseSerializer):
477
477
"""
@@ -542,7 +542,7 @@ The `default` argument is also available and always implies that the field is no
542
542
543
543
#### Coercing output types.
544
544
545
-
The previous field implementations did not forcibly coerce returned values into the correct type in many cases. For example, an `IntegerField` would return a string output if the attribute value was a string. We now more strictly coerce to the correct return type, leading to more constrained and expected behavior.
545
+
The previous field implementations did not forcibly coerce returned values into the correct type in many cases. For example, an `IntegerField` would return a string output if the attribute value was a string. We now more strictly coerce to the correct return type, leading to more constrained and expected behavior.
546
546
547
547
#### The `ListField` class.
548
548
@@ -695,7 +695,7 @@ These classes are documented in the [Validators](../api-guide/validators.md) sec
695
695
696
696
The view logic for the default method handlers has been significantly simplified, due to the new serializers API.
697
697
698
-
#### Changes to pre/post save hooks.
698
+
#### Changes to pre/post save hooks.
699
699
700
700
The `pre_save` and `post_save` hooks no longer exist, but are replaced with `perform_create(self, serializer)` and `perform_update(self, serializer)`.
701
701
@@ -887,4 +887,4 @@ The 3.2 release is planned to introduce an alternative admin-style interface to
887
887
888
888
You can follow development on the GitHub site, where we use [milestones to indicate planning timescales](https://github.com/tomchristie/django-rest-framework/milestones).
0 commit comments