Validators¶
The validators module contains a set of fields
validators.
A validator is any callable object which receives a value as the
target for the validation. If the validation fails then should raise an
errors.ValidationError
exception with an error message.
Validators are passed to fields.Field
and subclasses as possitional
arguments.
-
class
validators.
Boolean
¶ This validator forces fields values to be an instance of bool.
-
class
validators.
Email
¶ This validator forces fields values to be strings and match a valid email address.
-
class
validators.
Float
¶ This validator forces fields values to be an instance of float.
-
class
validators.
In
(choices)¶ This validator forces fields to have their value in the given list.
Parameters: choices – A list of possible values.
-
class
validators.
Integer
¶ This validator forces fields values to be an instance of int.
-
class
validators.
List
(*validators)¶ This validator forces field values to be a
list
. Also a list of innervalidators
could be specified to validate each list element. For example, to validate a list ofmodels.Model
you could do:books = fields.Field(validators.List(validators.Model(YourBookModel)))
Parameters: *validators – A list of inner validators as possitional arguments.
-
class
validators.
Model
(model)¶ This validator forces fields values to be an instance of the given
models.Model
subclass and also performs a validation in the entire model object.Parameters: model – A subclass of models.Model
-
class
validators.
Required
¶ This validator forces fields to have a value other than
None
.
-
class
validators.
String
¶ This validator forces fields values to be an instance of basestring.