mirror of
https://github.com/ae-utbm/sith.git
synced 2026-06-05 07:39:21 +00:00
add translations
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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",
|
||||
),
|
||||
),
|
||||
]
|
||||
|
||||
@@ -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}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user