DEV Community

Jaweher Ben Salah
Jaweher Ben Salah

Posted on

UniqueValidator in drf

6

my model has a field:

name = models.CharField(max_length=255, blank=True, null=True)

in serializer, I am trying to raise a unique validation error

name = serializers.CharField(validators=[UniqueValidator(queryset=Department.objects.all()
                                        message=("Name already exists"))])

but it does not work, because the data comes to the serializer in this format name: {en: "drink"}, in db fields are…

Top comments (0)