summaryrefslogtreecommitdiff
path: root/sublab_project/calendarium/models.py
blob: 1cd0665f51d3f0c675009a09cdfe3cd12afe6eb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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.')