Django-rest-framework: Disable validation on serializer completely (nested)

Created on 4 Apr 2017  路  1Comment  路  Source: encode/django-rest-framework

I am looking for a way to disable validation on a serializer in a nested way.
For example wth this code:

class SerializerTwo(serializers.Serializer):
    value_two = serializers.CharField()

class SerializerOne(serializers.Serializer):
    value_one = serializers.CharField()
    nested_value = AnotherSerializer(required=False)

I want to be able to post data of the form

{
    value_one: "abc",
    value_two: {
          // this shouldn't matter
    }
}

And not receive any validation errors no matter on how I set up the validation. I want this because I wrote my own validation methods that are shared with another part of the codebase. Hence, I don't want DRF interfering with that flow.

>All comments

Don't use a serializer for the nested field. Use a DictField, or something else that reflects a more lenient set of validation constraints.

Was this page helpful?
0 / 5 - 0 ratings