From 7e960881ae6cbcd709538dcd73e4fd89e33507d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Zapke-Gru=CC=88ndemann?= Date: Wed, 4 Jan 2012 23:58:44 +0100 Subject: Added model, admin, tests and tasks for calendarium. --- sublab_project/calendarium/models.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'sublab_project/calendarium/models.py') diff --git a/sublab_project/calendarium/models.py b/sublab_project/calendarium/models.py index 71a8362..1cd0665 100644 --- a/sublab_project/calendarium/models.py +++ b/sublab_project/calendarium/models.py @@ -1,3 +1,31 @@ from django.db import models -# Create your models here. + +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.') -- cgit v1.2.1