Fix: editing of existing custom fields violates throws unique error

This commit is contained in:
shamoon 2024-07-06 12:58:50 -07:00
parent 0deb8a11d6
commit 7fe76656f2

View File

@ -463,7 +463,14 @@ class CustomFieldSerializer(serializers.ModelSerializer):
"name",
self.instance.name if hasattr(self.instance, "name") else None,
)
if ("name" in attrs) and self.Meta.model.objects.filter(
objects = (
self.Meta.model.objects.exclude(
pk=self.instance.pk,
)
if self.instance is not None
else self.Meta.model.objects.all()
)
if ("name" in attrs) and objects.filter(
name=name,
).exists():
raise serializers.ValidationError(