Added some validation to the Event model

This commit is contained in:
Raphael Michel
2015-10-21 16:39:28 +02:00
parent 9d30f9fc64
commit 3201afe64f
2 changed files with 9 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ import uuid
from datetime import datetime
from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.validators import RegexValidator
from django.db import models
from django.template.defaultfilters import date as _date
@@ -101,6 +102,13 @@ class Event(Versionable):
self.get_cache().clear()
return obj
def clean(self):
if self.presale_start and self.presale_end and self.presale_start > self.presale_end:
raise ValidationError({'presale_end': _('The end of the presale period has to be later than it\'s start.')})
if self.date_from and self.date_to and self.date_from > self.date_to:
raise ValidationError({'date_to': _('The end of the event has to be later than it\'s start.')})
super().clean()
def get_plugins(self) -> "list[str]":
"""
Get the names of the plugins activated for this event as a list.