From f3920957eb6efa0fae1397c007f4f358c7269981 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Thu, 19 Nov 2020 18:40:22 +0100 Subject: [PATCH] =?UTF-8?q?Premier=20draft=20de=20mod=C3=A8les?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements-dev.txt | 1 + requirements.txt | 2 +- votes/models.py | 46 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 7136449..fe79b52 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1 +1,2 @@ +-r requirements.txt django-debug-toolbar \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 2cc2e21..c5e348d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -django=2.2.* \ No newline at end of file +django==2.2.* \ No newline at end of file diff --git a/votes/models.py b/votes/models.py index 71a8362..c1baae9 100644 --- a/votes/models.py +++ b/votes/models.py @@ -1,3 +1,47 @@ 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)