validator
Decorate methods on the class indicating that they should be used to validate fields.
def validator(
__field: str,
*fields: str,
pre: bool = False,
each_item: bool = False,
always: bool = False,
check_fields: bool | None = None,
allow_reuse: bool = False
) - > Callable
Decorate methods on the class indicating that they should be used to validate fields.
Parameters
| Name | Type | Description |
|---|---|---|
| __field | str | The first field the validator should be called on; this is separate from fields to ensure an error is raised if you don't pass at least one. |
| *fields | str | Additional field(s) the validator should be called on. |
| pre | bool = False | Whether this validator should be called before the standard validators (else after). |
| each_item | bool = False | For complex objects (sets, lists etc.) whether to validate individual elements rather than the whole object. |
| always | bool = False | Whether this method and other validators should be called even if the value is missing. |
| check_fields | `bool | None` = None |
| allow_reuse | bool = False | Whether to track and raise an error if another validator refers to the decorated function. |
Returns
| Type | Description |
|---|---|
Callable | A decorator that can be used to decorate a function to be used as a validator. |