Merge pull request #2070 from bagerard/improve_doc_of_custom_field_validation

Document the custom field validation feature
This commit is contained in:
erdenezul 2019-06-05 22:30:40 +02:00 committed by GitHub
commit c1c81fc07b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -176,6 +176,21 @@ arguments can be set on all fields:
class Shirt(Document): class Shirt(Document):
size = StringField(max_length=3, choices=SIZE) size = StringField(max_length=3, choices=SIZE)
:attr:`validation` (Optional)
A callable to validate the value of the field.
The callable takes the value as parameter and should raise a ValidationError
if validation fails
e.g ::
def _not_empty(val):
if not val:
raise ValidationError('value can not be empty')
class Person(Document):
name = StringField(validation=_not_empty)
:attr:`**kwargs` (Optional) :attr:`**kwargs` (Optional)
You can supply additional metadata as arbitrary additional keyword You can supply additional metadata as arbitrary additional keyword
arguments. You can not override existing attributes, however. Common arguments. You can not override existing attributes, however. Common