Mercurial > public > sg101
comparison bulletins/models.py @ 581:ee87ea74d46b
For Django 1.4, rearranged project structure for new manage.py.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 05 May 2012 17:10:48 -0500 |
parents | gpp/bulletins/models.py@65016249bf35 |
children |
comparison
equal
deleted
inserted
replaced
580:c525f3e0b5d0 | 581:ee87ea74d46b |
---|---|
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 class Meta: | |
35 ordering = ('-start_date', ) | |
36 | |
37 def __unicode__(self): | |
38 return self.title |