Skip to content

Commit 78367ba

Browse files
tddycocarltongibson
authored andcommitted
Always fully qualify ValidationError in docs (#5751)
1 parent 2709de1 commit 78367ba

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

docs/api-guide/serializers.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ Your `validate_<field_name>` methods should return the validated value or raise
197197

198198
#### Object-level validation
199199

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:
201201

202202
from rest_framework import serializers
203203

@@ -906,7 +906,7 @@ Or use it to serialize multiple instances:
906906

907907
##### Read-write `BaseSerializer` classes
908908

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.
910910

911911
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`.
912912

@@ -921,15 +921,15 @@ Here's a complete example of our previous `HighScoreSerializer`, that's been upd
921921

922922
# Perform the data validation.
923923
if not score:
924-
raise ValidationError({
924+
raise serializers.ValidationError({
925925
'score': 'This field is required.'
926926
})
927927
if not player_name:
928-
raise ValidationError({
928+
raise serializers.ValidationError({
929929
'player_name': 'This field is required.'
930930
})
931931
if len(player_name) > 10:
932-
raise ValidationError({
932+
raise serializers.ValidationError({
933933
'player_name': 'May not be more than 10 characters.'
934934
})
935935

0 commit comments

Comments
 (0)