From 9973f15003004a2b26da207af7d05f77945a18af Mon Sep 17 00:00:00 2001 From: georg Date: Wed, 3 Feb 2021 10:00:24 +0100 Subject: [PATCH] allow not selected --- survey/forms.py | 4 ++-- survey/models/question.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/survey/forms.py b/survey/forms.py index a3dba3e8..a0348aca 100644 --- a/survey/forms.py +++ b/survey/forms.py @@ -305,8 +305,8 @@ def clean_choices(self, s): value = self.cleaned_data print(value) for q in s.questions.all(): - if q.type in ["select-multiple"]: - # Only for SELECT_MULTIPlE + if q.type in ["select-multiple"] and q.maximum_choices: + # Only for SELECT_MULTIPlE and if maximum_choices is set question = q max = question.maximum_choices if value.get(f"question_{question.id}"): diff --git a/survey/models/question.py b/survey/models/question.py index e5f0a4b3..b697591e 100644 --- a/survey/models/question.py +++ b/survey/models/question.py @@ -78,7 +78,7 @@ class Question(models.Model): survey = models.ForeignKey(Survey, on_delete=models.CASCADE, verbose_name=_("Survey"), related_name="questions") type = models.CharField(_("Type"), max_length=200, choices=QUESTION_TYPES, default=TEXT) choices = models.TextField(_("Choices"), blank=True, null=True, help_text=CHOICES_HELP_TEXT) - maximum_choices = models.IntegerField(_("Maximum possible Answers")) + maximum_choices = models.IntegerField(_("Maximum possible Answers"), blank=True, null=True) class Meta: verbose_name = _("question")