Add default_value model field, validation and form field

This commit is contained in:
Johan von Forstner
2018-05-26 13:07:31 +02:00
committed by johan12345
parent 5f15ebc46f
commit 3483c522da
3 changed files with 11 additions and 0 deletions

View File

@@ -963,6 +963,11 @@ class Question(LoggedModel):
'Question', null=True, blank=True, on_delete=models.SET_NULL, related_name='dependent_questions'
)
dependency_value = models.TextField(null=True, blank=True)
default_value = models.TextField(
verbose_name=_('Default answer'),
help_text=_('The question will be filled with this response by default'),
null=True, blank=True,
)
class Meta:
verbose_name = _("Question")
@@ -980,6 +985,10 @@ class Question(LoggedModel):
def clean_identifier(self, code):
Question._clean_identifier(self.event, code, self)
def clean(self):
if self.default_value is not None:
self.clean_answer(self.default_value)
@staticmethod
def _clean_identifier(event, code, instance=None):
qs = Question.objects.filter(event=event, identifier__iexact=code)

View File

@@ -80,6 +80,7 @@ class QuestionForm(I18nModelForm):
'help_text',
'type',
'required',
'default_value',
'ask_during_checkin',
'identifier',
'items',

View File

@@ -107,6 +107,7 @@
<fieldset>
<legend>{% trans "Advanced settings" %}</legend>
{% bootstrap_field form.help_text layout="control" %}
{% bootstrap_field form.default_value layout="control" %}
{% bootstrap_field form.identifier layout="control" %}
{% bootstrap_field form.ask_during_checkin layout="control" %}