From 70d6e763b00ea2240cb9e5d4917c38af2bc78c10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastien=20G=C3=A9rard?= Date: Wed, 5 Jun 2019 22:06:37 +0200 Subject: [PATCH] Document the custom field validation feature --- docs/guide/defining-documents.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/guide/defining-documents.rst b/docs/guide/defining-documents.rst index 911de36d..ae9d3b36 100644 --- a/docs/guide/defining-documents.rst +++ b/docs/guide/defining-documents.rst @@ -176,6 +176,21 @@ arguments can be set on all fields: class Shirt(Document): 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) You can supply additional metadata as arbitrary additional keyword arguments. You can not override existing attributes, however. Common