Premier draft de modèles

This commit is contained in:
Ludovic Stephan 2020-11-19 18:40:22 +01:00
parent e62178f508
commit f3920957eb
3 changed files with 47 additions and 2 deletions

View file

@ -1 +1,2 @@
-r requirements.txt
django-debug-toolbar django-debug-toolbar

View file

@ -1 +1 @@
django=2.2.* django==2.2.*

View file

@ -1,3 +1,47 @@
from django.db import models from django.db import models
from django.utils.translation import gettext_lazy as _
from django.contrib.auth import get_user_model
# Create your models here. 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
)
counted = models.BooleanField(_("dépouillée"), default=False)
results_public = models.BooleanField(_("résultats publics"), default=False)
archived = models.BooleanField(_("archivée"), default=False)
class Question(models.Model):
election = models.ForeignKey(Election, on_delete=models.CASCADE)
text = models.TextField(_("question"), blank=False)
# TODO: add voting type
class Option(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
text = models.TextField(_("texte"), blank=False)
class Vote(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
votes = models.ManyToManyField(Option, through="OptionVote")
class OptionVote(models.Model):
vote = models.ForeignKey(Vote, on_delete=models.CASCADE)
option = models.ForeignKey(Option, on_delete=models.CASCADE)
# Préparation pour condorcet ?
ranking = models.PositiveSmallIntegerField(_("rang"), default=0)