From 9c89bde9a0921e033aba1d6e98ce2e29aaab4359 Mon Sep 17 00:00:00 2001 From: imperosol Date: Fri, 5 Jun 2026 00:14:13 +0200 Subject: [PATCH] add translations --- election/forms.py | 9 --------- .../0006_role_club_role_alter_role_description.py | 9 +++++++++ election/models.py | 10 ++++++++++ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/election/forms.py b/election/forms.py index 9595e098..868bbe72 100644 --- a/election/forms.py +++ b/election/forms.py @@ -106,15 +106,6 @@ class RoleForm(forms.ModelForm): is_board=True, club__in=election.clubs.all() ) - def clean(self): - cleaned_data = super().clean() - title = cleaned_data.get("title") - election = cleaned_data.get("election") - if Role.objects.filter(title=title, election=election).exists(): - raise forms.ValidationError( - _("This role already exists for this election"), code="invalid" - ) - class ElectionListForm(forms.ModelForm): class Meta: diff --git a/election/migrations/0006_role_club_role_alter_role_description.py b/election/migrations/0006_role_club_role_alter_role_description.py index 8b9e004e..1b7aa009 100644 --- a/election/migrations/0006_role_club_role_alter_role_description.py +++ b/election/migrations/0006_role_club_role_alter_role_description.py @@ -50,4 +50,13 @@ class Migration(migrations.Migration): default=1, verbose_name="max choice" ), ), + migrations.AddConstraint( + model_name="role", + constraint=models.UniqueConstraint( + fields=("title", "election"), + name="title_election_unique_constraint", + violation_error_code="invalid", + violation_error_message="This role already exists for this election", + ), + ), ] diff --git a/election/models.py b/election/models.py index f9a0c9c7..d1b92154 100644 --- a/election/models.py +++ b/election/models.py @@ -130,6 +130,16 @@ class Role(OrderedModel): order_with_respect_to = "election" + class Meta(OrderedModel.Meta): + constraints = [ + models.UniqueConstraint( + fields=["title", "election"], + name="title_election_unique_constraint", + violation_error_message=_("This role already exists for this election"), + violation_error_code="invalid", + ) + ] + def __str__(self): return f"{self.title} - {self.election.title}"