Skip to content

Commit

Permalink
Add ValidateFuzzyUnique validator to CategoryModelSerializer cat field
Browse files Browse the repository at this point in the history
  • Loading branch information
Termuellinator committed Oct 16, 2023
1 parent 0d99a1a commit 00af911
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions apps/post/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@


class CategoryModelSerializer(serializers.ModelSerializer):
cat = serializers.CharField(validators=[
validators.ValidateFuzzyUnique(
queryset=models.Category.objects.all(),
target_field="cat",
source="serializer"
)
])
class Meta:
model = models.Category
fields = "__all__"
Expand Down

0 comments on commit 00af911

Please sign in to comment.