From eb7f5def6ec3195d5a4e0e34776446d155e321ab Mon Sep 17 00:00:00 2001 From: imperosol Date: Sun, 31 May 2026 12:24:42 +0200 Subject: [PATCH] feat: link election `Role` to `ClubRole` --- ...6_role_club_role_alter_role_description.py | 53 +++++++++++++++++++ election/models.py | 28 ++++++++-- 2 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 election/migrations/0006_role_club_role_alter_role_description.py diff --git a/election/migrations/0006_role_club_role_alter_role_description.py b/election/migrations/0006_role_club_role_alter_role_description.py new file mode 100644 index 00000000..8b9e004e --- /dev/null +++ b/election/migrations/0006_role_club_role_alter_role_description.py @@ -0,0 +1,53 @@ +# Generated by Django 5.2.14 on 2026-05-30 20:00 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("club", "0017_linktype_clublink"), + ("election", "0005_alter_candidature_program_alter_candidature_user"), + ] + + operations = [ + migrations.AddField( + model_name="election", + name="clubs", + field=models.ManyToManyField( + help_text="The club(s) this election is held for.", + related_name="elections", + to="club.club", + verbose_name="clubs", + ), + ), + migrations.AddField( + model_name="role", + name="club_role", + field=models.ForeignKey( + blank=True, + help_text=( + "A club role. Filling this will allow automatic " + "completion of title and description, " + "and automatic assignation after the elections." + ), + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="election_roles", + to="club.clubrole", + verbose_name="club role", + ), + ), + migrations.AlterField( + model_name="role", + name="description", + field=models.TextField(blank=True, default="", verbose_name="description"), + ), + migrations.AlterField( + model_name="role", + name="max_choice", + field=models.PositiveSmallIntegerField( + default=1, verbose_name="max choice" + ), + ), + ] diff --git a/election/models.py b/election/models.py index 3e807ff6..c1c42dc1 100644 --- a/election/models.py +++ b/election/models.py @@ -5,6 +5,7 @@ from django.utils.functional import cached_property from django.utils.translation import gettext_lazy as _ from ordered_model.models import OrderedModel +from club.models import Club, ClubRole from core.models import Group, User @@ -13,6 +14,12 @@ class Election(models.Model): title = models.CharField(_("title"), max_length=255) description = models.TextField(_("description"), null=True, blank=True) + clubs = models.ManyToManyField( + Club, + related_name="elections", + verbose_name=_("clubs"), + help_text=_("The club(s) this election is held for."), + ) start_candidature = models.DateTimeField(_("start candidature"), blank=False) end_candidature = models.DateTimeField(_("end candidature"), blank=False) start_date = models.DateTimeField(_("start date"), blank=False) @@ -96,7 +103,7 @@ class Election(models.Model): class Role(OrderedModel): - """This class allows to create a new role avaliable for a candidature.""" + """This class allows to create a new role available for a candidature.""" election = models.ForeignKey( Election, @@ -105,8 +112,23 @@ class Role(OrderedModel): on_delete=models.CASCADE, ) title = models.CharField(_("title"), max_length=255) - description = models.TextField(_("description"), null=True, blank=True) - max_choice = models.IntegerField(_("max choice"), default=1) + description = models.TextField(_("description"), default="", blank=True) + max_choice = models.PositiveSmallIntegerField(_("max choice"), default=1) + club_role = models.ForeignKey( + ClubRole, + related_name="election_roles", + verbose_name=_("club role"), + help_text=_( + "A club role. Filling this will allow automatic " + "completion of title and description, " + "and automatic assignation after the elections." + ), + on_delete=models.CASCADE, + null=True, + blank=True, + ) + + order_with_respect_to = "election" def __str__(self): return f"{self.title} - {self.election.title}"