gremmie@1: """Models for the bulletins app. gremmie@1: Bulletins allow the sited admins to display and manage important notices for the website. gremmie@1: """ gremmie@1: gremmie@1: import datetime gremmie@1: from django.db import models gremmie@1: from django.db.models import Q gremmie@1: gremmie@1: gremmie@1: class BulletinManager(models.Manager): gremmie@1: """Manager for the Bulletin model.""" gremmie@1: gremmie@1: def get_current(self): gremmie@1: now = datetime.datetime.now() gremmie@1: return self.filter( gremmie@1: Q(is_enabled=True), gremmie@1: Q(start_date__lte=now), gremmie@1: Q(end_date__isnull=True) | Q(end_date__gte=now)) gremmie@1: gremmie@1: gremmie@1: class Bulletin(models.Model): gremmie@1: """Model to represent site bulletins.""" gremmie@1: title = models.CharField(max_length=200) gremmie@1: text = models.TextField() gremmie@1: start_date = models.DateTimeField(db_index=True, gremmie@1: help_text='Start date for when the bulletin will be active.',) gremmie@1: end_date = models.DateTimeField(blank=True, null=True, db_index=True, gremmie@1: help_text='End date for the bulletin. Leave blank to keep it open-ended.') gremmie@1: is_enabled = models.BooleanField(default=True, db_index=True, gremmie@1: help_text='Check to allow the bulletin to be viewed on the site.') gremmie@1: gremmie@1: objects = BulletinManager() gremmie@1: gremmie@1: def __unicode__(self): gremmie@1: return self.title gremmie@1: gremmie@1: class Meta: gremmie@1: ordering = ('-start_date', )