kadenios/elections/models.py
Ludovic Stephan 38251ba37e Rename app
2020-11-20 17:45:35 +01:00

42 lines
1.3 KiB
Python

from django.db import models
from django.utils.translation import gettext_lazy as _
from django.contrib.auth import get_user_model
User = get_user_model()
class Election(models.Model):
name = models.CharField(_("nom"), max_length=255)
short_name = models.SlugField(_("nom bref"), unique=True)
description = models.TextField(_("description"), blank=True)
start_time = models.DateTimeField(_("date et heure de début"))
end_time = models.DateTimeField(_("date et heure de fin"))
created_by = models.ForeignKey(
User, on_delete=models.SET_NULL, blank=True, null=True
)
results_public = models.BooleanField(_("résultats publics"), default=False)
tallied = models.BooleanField(_("dépouillée"), default=False)
# TODO : cache tally or recompute it each time ?
archived = models.BooleanField(_("archivée"), default=False)
class Question(models.Model):
election = models.ForeignKey(
Election, related_name="questions", on_delete=models.CASCADE
)
text = models.TextField(_("question"), blank=False)
class Option(models.Model):
question = models.ForeignKey(
Question, related_name="options", on_delete=models.CASCADE
)
text = models.TextField(_("texte"), blank=False)
voters = models.ManyToManyField(
User,
related_name="votes",
)