comparison gpp/bulletins/models.py @ 1:dbd703f7d63a

Initial import of sg101 stuff from private repository.
author gremmie
date Mon, 06 Apr 2009 02:43:12 +0000
parents
children e249b5f9d180
comparison
equal deleted inserted replaced
0:900ba3c7b765 1:dbd703f7d63a
1 """Models for the bulletins app.
2 Bulletins allow the sited admins to display and manage important notices for the website.
3 """
4
5 import datetime
6 from django.db import models
7 from django.db.models import Q
8
9
10 class BulletinManager(models.Manager):
11 """Manager for the Bulletin model."""
12
13 def get_current(self):
14 now = datetime.datetime.now()
15 return self.filter(
16 Q(is_enabled=True),
17 Q(start_date__lte=now),
18 Q(end_date__isnull=True) | Q(end_date__gte=now))
19
20
21 class Bulletin(models.Model):
22 """Model to represent site bulletins."""
23 title = models.CharField(max_length=200)
24 text = models.TextField()
25 start_date = models.DateTimeField(db_index=True,
26 help_text='Start date for when the bulletin will be active.',)
27 end_date = models.DateTimeField(blank=True, null=True, db_index=True,
28 help_text='End date for the bulletin. Leave blank to keep it open-ended.')
29 is_enabled = models.BooleanField(default=True, db_index=True,
30 help_text='Check to allow the bulletin to be viewed on the site.')
31
32 objects = BulletinManager()
33
34 def __unicode__(self):
35 return self.title
36
37 class Meta:
38 ordering = ('-start_date', )