mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-18 14:02:15 +00:00
Swap to better method of validating uniqueness of cable types
SCOPE, Arona, damn it
This commit is contained in:
@@ -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
|
||||
|
||||
17
assets/migrations/0022_alter_cabletype_unique_together.py
Normal file
17
assets/migrations/0022_alter_cabletype_unique_together.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# Generated by Django 3.2.11 on 2022-01-12 19:11
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('assets', '0021_auto_20210302_1204'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterUniqueTogether(
|
||||
name='cabletype',
|
||||
unique_together={('plug', 'socket', 'circuits', 'cores')},
|
||||
),
|
||||
]
|
||||
@@ -75,6 +75,7 @@ class CableType(models.Model):
|
||||
|
||||
class Meta:
|
||||
ordering = ['plug', 'socket', '-circuits']
|
||||
unique_together = ['plug', 'socket', 'circuits', 'cores']
|
||||
|
||||
def __str__(self):
|
||||
if self.plug and self.socket:
|
||||
|
||||
Reference in New Issue
Block a user