Logo

dev-resources.site

for different kinds of informations.

UniqueValidator in drf

Published at
1/8/2024
Categories
Author
Jaweher Ben Salah
Categories
1 categories in total
open
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…

Featured ones: