diff --git a/src/vote/migrations/0006_event_status.py b/src/vote/migrations/0006_event_status.py new file mode 100644 index 0000000..a726f02 --- /dev/null +++ b/src/vote/migrations/0006_event_status.py @@ -0,0 +1,34 @@ +# Generated by Django 5.2.7 on 2026-01-21 05:18 + +from django.db import migrations, models + + +def set_default_status(apps, schema_editor): + Event = apps.get_model("vote", "Event") + for event in Event.objects.all(): + if event.closed: + event.status = "CL" + else: + event.status = "RE" + event.save() + + +class Migration(migrations.Migration): + dependencies = [ + ("vote", "0005_event_show_results"), + ] + + operations = [ + migrations.AddField( + model_name="event", + name="status", + field=models.CharField( + choices=[("RE", "Registring"), ("VO", "Voting"), ("CL", "Closed")], + default="RE", + max_length=2, + ), + ), + migrations.RunPython( + set_default_status, reverse_code=migrations.RunPython.noop + ), + ] diff --git a/src/vote/models.py b/src/vote/models.py index 5fc545c..3ebaf5a 100644 --- a/src/vote/models.py +++ b/src/vote/models.py @@ -2,6 +2,12 @@ from django.db import models from django.db.models import UniqueConstraint +EVENT_STATUS_CHOICES = { + "RE": "Registring", + "VO": "Voting", + "CL": "Closed", +} + class Event(models.Model): share_token = models.UUIDField(default=uuid.uuid4, editable=False) @@ -12,6 +18,7 @@ class Event(models.Model): show_results = models.BooleanField(default=False) closed = models.DateTimeField(null=True) electoral_system = models.CharField(max_length=2) + status = models.CharField(max_length=2, choices=EVENT_STATUS_CHOICES, default="RE") class Ballot(models.Model):