diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bulletins/models.py	Sat May 05 17:10:48 2012 -0500
@@ -0,0 +1,38 @@
+"""Models for the bulletins app.
+Bulletins allow the sited admins to display and manage important notices for the website.
+"""
+
+import datetime
+from django.db import models
+from django.db.models import Q
+
+
+class BulletinManager(models.Manager):
+    """Manager for the Bulletin model."""
+
+    def get_current(self):
+        now = datetime.datetime.now()
+        return self.filter(
+                Q(is_enabled=True),
+                Q(start_date__lte=now),
+                Q(end_date__isnull=True) | Q(end_date__gte=now))
+
+
+class Bulletin(models.Model):
+    """Model to represent site bulletins."""
+    title = models.CharField(max_length=200)
+    text = models.TextField()
+    start_date = models.DateTimeField(db_index=True,
+            help_text='Start date for when the bulletin will be active.',)
+    end_date = models.DateTimeField(blank=True, null=True, db_index=True,
+            help_text='End date for the bulletin. Leave blank to keep it open-ended.')
+    is_enabled = models.BooleanField(default=True, db_index=True,
+            help_text='Check to allow the bulletin to be viewed on the site.')
+
+    objects = BulletinManager()
+
+    class Meta:
+        ordering = ('-start_date', )
+
+    def __unicode__(self):
+        return self.title