From 4704da9a1acf3cbf1b1b1396821fa6ee61e0ffce Mon Sep 17 00:00:00 2001 From: Nic Young Date: Thu, 10 Sep 2015 17:17:33 -0700 Subject: [PATCH] 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`. --- docs/api-guide/serializers.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md index abdb67afa..1ac845901 100644 --- a/docs/api-guide/serializers.md +++ b/docs/api-guide/serializers.md @@ -189,6 +189,12 @@ Your `validate_` methods should return the validated value or raise raise serializers.ValidationError("Blog post is not about Django") return value +--- + +**Note:** If your `` 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 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: