diff --git a/elections/forms.py b/elections/forms.py index f8d5a81..7da7185 100644 --- a/elections/forms.py +++ b/elections/forms.py @@ -50,7 +50,7 @@ class VoterMailForm(forms.Form): class QuestionForm(forms.ModelForm): class Meta: model = Question - fields = ["text"] + fields = ["text", "type"] widgets = {"text": forms.TextInput} diff --git a/elections/migrations/0011_question_type.py b/elections/migrations/0011_question_type.py new file mode 100644 index 0000000..64f4765 --- /dev/null +++ b/elections/migrations/0011_question_type.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.19 on 2021-03-19 10:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("elections", "0010_blank_voters"), + ] + + operations = [ + migrations.AddField( + model_name="question", + name="type", + field=models.CharField( + choices=[("assentiment", "Assentiment")], + default="assentiment", + max_length=11, + verbose_name="type de question", + ), + ), + ] diff --git a/elections/models.py b/elections/models.py index 26559cf..7bd04e1 100644 --- a/elections/models.py +++ b/elections/models.py @@ -3,7 +3,8 @@ from django.contrib.auth.models import AbstractUser from django.db import models from django.utils.translation import gettext_lazy as _ -from .staticdefs import CONNECTION_METHODS +from .staticdefs import CONNECTION_METHODS, QUESTION_TYPES +from .utils import choices_length # ############################################################################# # Models regarding an election @@ -54,6 +55,12 @@ class Question(models.Model): Election, related_name="questions", on_delete=models.CASCADE ) text = models.TextField(_("question"), blank=False) + type = models.CharField( + _("type de question"), + choices=QUESTION_TYPES, + default="assentiment", + max_length=choices_length(QUESTION_TYPES), + ) # We cache the maximum number of votes for an option max_votes = models.PositiveSmallIntegerField( _("nombre maximal de votes reçus"), default=0 @@ -74,6 +81,7 @@ class Option(models.Model): Question, related_name="options", on_delete=models.CASCADE ) text = models.TextField(_("texte"), blank=False) + voters = models.ManyToManyField( settings.AUTH_USER_MODEL, related_name="votes", diff --git a/elections/staticdefs.py b/elections/staticdefs.py index 6699d54..73a4bcf 100644 --- a/elections/staticdefs.py +++ b/elections/staticdefs.py @@ -17,3 +17,7 @@ CONNECTION_METHODS = { "pwd": _("mot de passe"), "cas": _("CAS"), } + +QUESTION_TYPES = [ + ("assentiment", _("Assentiment")), +] diff --git a/elections/templates/elections/election_admin.html b/elections/templates/elections/election_admin.html index acf2a8c..cd5d03f 100644 --- a/elections/templates/elections/election_admin.html +++ b/elections/templates/elections/election_admin.html @@ -112,6 +112,7 @@ {% trans "Modifier" %} {% endif %} + {{ q.get_type_display }} {# Liste des options possibles #} @@ -177,6 +178,17 @@ + +