From b6ef7c1d890234d1ce443f90994dec766d5e7240 Mon Sep 17 00:00:00 2001 From: Arona Jones Date: Thu, 29 Jul 2021 23:15:09 +0100 Subject: [PATCH] Force traininglevelqualifications to be unique --- assets/forms.py | 2 +- training/models.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/assets/forms.py b/assets/forms.py index c98b7707..c7f7fb5b 100644 --- a/assets/forms.py +++ b/assets/forms.py @@ -45,7 +45,7 @@ class CableTypeForm(forms.ModelForm): model = models.CableType fields = '__all__' - def clean(self): + 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... diff --git a/training/models.py b/training/models.py index 674d3776..adeeecba 100644 --- a/training/models.py +++ b/training/models.py @@ -152,3 +152,6 @@ class TrainingLevelQualification(models.Model): def __str__(self): return "{} qualified as a {}".format(self.trainee, self.level) + + class Meta: + unique_together = ["trainee", "level"]