Swap to better method of validating uniqueness of cable types

SCOPE, Arona, damn it
This commit is contained in:
2022-01-12 19:15:38 +00:00
parent b4c5493705
commit aa6bb8410e
3 changed files with 18 additions and 8 deletions

View File

@@ -45,11 +45,3 @@ class CableTypeForm(forms.ModelForm):
class Meta:
model = models.CableType
fields = '__all__'
def clean(self): # TODO Does unique_together work better than this?
form_data = self.cleaned_data
queryset = models.CableType.objects.filter(Q(plug=form_data['plug']) & Q(socket=form_data['socket']) & Q(circuits=form_data['circuits']) & Q(cores=form_data['cores']))
# Being identical to itself shouldn't count...
if queryset.exists() and self.instance.pk != queryset[0].pk:
raise forms.ValidationError("A cable type that exactly matches this one already exists, please use that instead.", code="notunique")
return form_data