Mercurial > public > sg101
annotate bulletins/models.py @ 1073:19d34242473e
Convert IRC page to V3 design.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 12 Apr 2016 19:49:47 -0500 |
parents | ee87ea74d46b |
children |
rev | line source |
---|---|
gremmie@1 | 1 """Models for the bulletins app. |
gremmie@1 | 2 Bulletins allow the sited admins to display and manage important notices for the website. |
gremmie@1 | 3 """ |
gremmie@1 | 4 |
gremmie@1 | 5 import datetime |
gremmie@1 | 6 from django.db import models |
gremmie@1 | 7 from django.db.models import Q |
gremmie@1 | 8 |
gremmie@1 | 9 |
gremmie@1 | 10 class BulletinManager(models.Manager): |
bgneal@54 | 11 """Manager for the Bulletin model.""" |
gremmie@1 | 12 |
bgneal@54 | 13 def get_current(self): |
bgneal@54 | 14 now = datetime.datetime.now() |
bgneal@54 | 15 return self.filter( |
bgneal@54 | 16 Q(is_enabled=True), |
bgneal@54 | 17 Q(start_date__lte=now), |
bgneal@54 | 18 Q(end_date__isnull=True) | Q(end_date__gte=now)) |
gremmie@1 | 19 |
gremmie@1 | 20 |
gremmie@1 | 21 class Bulletin(models.Model): |
bgneal@54 | 22 """Model to represent site bulletins.""" |
bgneal@54 | 23 title = models.CharField(max_length=200) |
bgneal@54 | 24 text = models.TextField() |
bgneal@54 | 25 start_date = models.DateTimeField(db_index=True, |
bgneal@54 | 26 help_text='Start date for when the bulletin will be active.',) |
bgneal@54 | 27 end_date = models.DateTimeField(blank=True, null=True, db_index=True, |
bgneal@54 | 28 help_text='End date for the bulletin. Leave blank to keep it open-ended.') |
bgneal@54 | 29 is_enabled = models.BooleanField(default=True, db_index=True, |
bgneal@54 | 30 help_text='Check to allow the bulletin to be viewed on the site.') |
gremmie@1 | 31 |
bgneal@54 | 32 objects = BulletinManager() |
gremmie@1 | 33 |
bgneal@54 | 34 class Meta: |
bgneal@54 | 35 ordering = ('-start_date', ) |
gremmie@1 | 36 |
bgneal@54 | 37 def __unicode__(self): |
bgneal@54 | 38 return self.title |