Force traininglevelqualifications to be unique

This commit is contained in:
2021-07-29 23:15:09 +01:00
parent 85f40b358a
commit b6ef7c1d89
2 changed files with 4 additions and 1 deletions

View File

@@ -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...

View File

@@ -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"]