[Django]-Django Rest Framework model serializer with out unique together validation

39👍

Django REST framework applies the UniqueTogetherValidator on the serializer. You can remove this by override the validators field in the serializer definition.

class ExampleSerializer(serializers.ModelSerializer):
    class Meta:
        validators = []

Note that this also removes the other unique-check validators that are applied on the model, which might not be the best idea. To avoid that, just override the get_unique_together_validators method on the serializer, to ensure only unique-together check is removed.

class ExampleSerializer(serializers.ModelSerializer):
    def get_unique_together_validators(self):
        """Overriding method to disable unique together checks"""
        return []

1👍

You need to remove the validator from the serializer’s list.

Although not exactly the same, the steps are explained here

Leave a comment