mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-17 03:51:03 +03:00
Add note about field level validation, fixes #3306
The documentation added warns the user that field level validation will be skipped if the field is declared on the model with the parameter `required=False`.
This commit is contained in:
parent
cd4c389d1f
commit
4704da9a1a
|
@ -189,6 +189,12 @@ Your `validate_<field_name>` methods should return the validated value or raise
|
||||||
raise serializers.ValidationError("Blog post is not about Django")
|
raise serializers.ValidationError("Blog post is not about Django")
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Note:** If your `<field_name>` is declared on your serializer with the parameter `required=False` then this validation step will not take place if the field is not included.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
#### Object-level validation
|
#### Object-level validation
|
||||||
|
|
||||||
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:
|
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:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user