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/api-guide/serializers.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -197,7 +197,7 @@ Your `validate_<field_name>` methods should return the validated value or raise
197
197
198
198
#### Object-level validation
199
199
200
-
To do any other validation that requires access to multiple fields, add a method called `.validate()` to your `Serializer` subclass. This method takes a single argument, which is a dictionary of field values. It should raise a `ValidationError` if necessary, or just return the validated values. For example:
200
+
To do any other validation that requires access to multiple fields, add a method called `.validate()` to your `Serializer` subclass. This method takes a single argument, which is a dictionary of field values. It should raise a `serializers.ValidationError` if necessary, or just return the validated values. For example:
201
201
202
202
from rest_framework import serializers
203
203
@@ -906,7 +906,7 @@ Or use it to serialize multiple instances:
906
906
907
907
##### Read-write `BaseSerializer` classes
908
908
909
-
To create a read-write serializer we first need to implement a `.to_internal_value()` method. This method returns the validated values that will be used to construct the object instance, and may raise a `ValidationError` if the supplied data is in an incorrect format.
909
+
To create a read-write serializer we first need to implement a `.to_internal_value()` method. This method returns the validated values that will be used to construct the object instance, and may raise a `serializers.ValidationError` if the supplied data is in an incorrect format.
910
910
911
911
Once you've implemented `.to_internal_value()`, the basic validation API will be available on the serializer, and you will be able to use `.is_valid()`, `.validated_data` and `.errors`.
912
912
@@ -921,15 +921,15 @@ Here's a complete example of our previous `HighScoreSerializer`, that's been upd
921
921
922
922
# Perform the data validation.
923
923
if not score:
924
-
raise ValidationError({
924
+
raise serializers.ValidationError({
925
925
'score': 'This field is required.'
926
926
})
927
927
if not player_name:
928
-
raise ValidationError({
928
+
raise serializers.ValidationError({
929
929
'player_name': 'This field is required.'
930
930
})
931
931
if len(player_name) > 10:
932
-
raise ValidationError({
932
+
raise serializers.ValidationError({
933
933
'player_name': 'May not be more than 10 characters.'
0 commit comments