diff --git a/elections/models.py b/elections/models.py
index 12593df..d90a6f4 100644
--- a/elections/models.py
+++ b/elections/models.py
@@ -7,6 +7,7 @@ from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _
from shared.auth import CONNECTION_METHODS
+from shared.json import Serializer
from shared.utils import choices_length
from .staticdefs import (
@@ -86,7 +87,7 @@ class Election(models.Model):
ordering = ["-start_date", "-end_date"]
-class Question(models.Model):
+class Question(Serializer, models.Model):
election = models.ForeignKey(
Election, related_name="questions", on_delete=models.CASCADE
)
@@ -110,6 +111,8 @@ class Question(models.Model):
blank=True,
)
+ serializable_fields = ["text_en", "text_fr", "type"]
+
def is_form_valid(self, vote_form):
validate_function = getattr(ValidateFunctions, VALIDATE_FUNCTIONS[self.type])
return vote_form.is_valid() and validate_function(vote_form)
@@ -154,7 +157,7 @@ class Question(models.Model):
ordering = ["id"]
-class Option(models.Model):
+class Option(Serializer, models.Model):
question = models.ForeignKey(
Question, related_name="options", on_delete=models.CASCADE
)
@@ -171,6 +174,8 @@ class Option(models.Model):
# For now, we store the amount of votes received after the election is tallied
nb_votes = models.PositiveSmallIntegerField(_("nombre de votes reçus"), default=0)
+ serializable_fields = ["text_fr", "text_en", "abbreviation"]
+
def save(self, *args, **kwargs):
# On enlève les espaces et on passe tout en majuscules
self.abbreviation = "".join(self.abbreviation.upper().split())
diff --git a/elections/templates/elections/admin/option.html b/elections/templates/elections/admin/option.html
index fc5a6e3..cae4b93 100644
--- a/elections/templates/elections/admin/option.html
+++ b/elections/templates/elections/admin/option.html
@@ -9,7 +9,7 @@
-
+
diff --git a/elections/templates/elections/admin/question.html b/elections/templates/elections/admin/question.html
index 2eea1a7..b7a6f26 100644
--- a/elections/templates/elections/admin/question.html
+++ b/elections/templates/elections/admin/question.html
@@ -21,7 +21,7 @@
-
+
@@ -56,7 +56,7 @@
{# Rajout d'une option #}
{% if q.election.start_date > current_time %}
-