Questions: validate that min < max (#4992)

* Questions: validate that min < max

* Update src/pretix/base/models/items.py

Co-authored-by: Richard Schreiber <schreiber@rami.io>

---------

Co-authored-by: Richard Schreiber <schreiber@rami.io>
This commit is contained in:
Raphael Michel
2025-04-13 18:25:40 +02:00
committed by GitHub
parent 3b0cd35c7a
commit 66dfa99e58

View File

@@ -1915,6 +1915,15 @@ class Question(LoggedModel):
if event != item.event:
raise ValidationError(_('One or more items do not belong to this event.'))
def clean(self):
if self.valid_date_max and self.valid_date_min and self.valid_date_min > self.valid_date_max:
raise ValidationError(_("The maximum date must not be before the minimum value."))
if self.valid_datetime_max and self.valid_datetime_min and self.valid_datetime_min > self.valid_datetime_max:
raise ValidationError(_("The maximum date must not be before the minimum value."))
if self.valid_number_max and self.valid_number_min and self.valid_number_min > self.valid_number_max:
raise ValidationError(_("The maximum value must not be lower than the minimum value."))
super().clean()
class QuestionOption(models.Model):
question = models.ForeignKey('Question', related_name='options', on_delete=models.CASCADE)