Validation

validate(cls, instance_or_dict, trusted_data=None, partial=False, strict=False, convert=True, context=None, **kwargs)

Validate some untrusted data using a model. Trusted data can be passed in the trusted_data parameter.

Parameters:
  • cls – The model class to use as source for validation. If given an instance, will also run instance-level validators on the data.
  • instance_or_dict – A dict or dict-like structure for incoming data.
  • partial – Allow partial data to validate; useful for PATCH requests. Essentially drops the required=True arguments from field definitions. Default: False
  • strict – Complain about unrecognized keys. Default: False
  • trusted_data – A dict-like structure that may contain already validated data.
  • convert – Controls whether to perform import conversion before validating. Can be turned off to skip an unnecessary conversion step if all values are known to have the right datatypes (e.g., when validating immediately after the initial import). Default: True
Returns:

data dict containing the valid raw_data plus trusted_data. If errors are found, they are raised as a ValidationError with a list of errors attached.

Usage

To learn more about how Validation is used, visit Using Validation