drf_braces.serializers.enforce_validation_serializer module

class drf_braces.serializers.enforce_validation_serializer.EnforceValidationFieldMixin[source]

Bases: object

Custom DRF field mixin which allows to ignore validation error if the field is not mandatory.

The field is mandatory when the parent serializer includes it in the must_validate_fields list or must_validate_fields list is completely omitted. If the list is omitted, then all fields in that serializer are mandatory and must validate.

run_validation(data=<class rest_framework.fields.empty>)[source]
drf_braces.serializers.enforce_validation_serializer.create_enforce_validation_serializer(serializer=None, **kwargs)[source]

Public function that creates a copy of a serializer which enforces must_validate_fields. The difference between this function and _create_enforce_validation_serializer is that this function can be used both as a direct decorator and decorator with parameters.

For example:

class MySerializer(BaseSerializer): pass

# or

class MySerializer(BaseSerializer): pass

# or