from django.db import models class Event(models.Model): """A calendar event. """ SOURCE_ADMIN = 'admin' SOURCE_IMPORT = 'import' name = models.CharField('Name', max_length=255) description = models.TextField('Beschreibung', blank=True) start = models.DateTimeField('Beginn') end = models.DateTimeField('Ende') source = models.CharField('Quelle', max_length=10, editable=False, default=SOURCE_IMPORT) class Meta: verbose_name = 'Termin' verbose_name_plural = 'Termine' ordering = ['start', 'end', 'name'] def __unicode__(self): return '%s (%s - %s)' % (self.name, self.start.strftime('%d.%m.%Y %T'), self.end.strftime('%d.%m.%Y %T')) def clean(self): """Checks if the start date is lower than the end date. """ from django.core.exceptions import ValidationError if self.start > self.end: raise ValidationError('Der Beginn darf nicht vor dem Ende liegen.')