annotate gpp/bulletins/models.py @ 197:2baadae33f2e

Got autocomplete working for the member search. Updated django and ran into a bug where url tags with comma separated kwargs starting consuming tons of CPU throughput. The work-around is to cut over to using spaces between arguments. This is now allowed to be consistent with other tags. Did some query optimization for the news app.
author Brian Neal <bgneal@gmail.com>
date Sat, 10 Apr 2010 04:32:24 +0000
parents 5c889b587416
children 65016249bf35
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
bgneal@54 8 from django.core.cache import cache
gremmie@1 9
gremmie@1 10
gremmie@1 11 class BulletinManager(models.Manager):
bgneal@54 12 """Manager for the Bulletin model."""
gremmie@1 13
bgneal@54 14 def get_current(self):
bgneal@54 15 now = datetime.datetime.now()
bgneal@54 16 return self.filter(
bgneal@54 17 Q(is_enabled=True),
bgneal@54 18 Q(start_date__lte=now),
bgneal@54 19 Q(end_date__isnull=True) | Q(end_date__gte=now))
gremmie@1 20
gremmie@1 21
gremmie@1 22 class Bulletin(models.Model):
bgneal@54 23 """Model to represent site bulletins."""
bgneal@54 24 title = models.CharField(max_length=200)
bgneal@54 25 text = models.TextField()
bgneal@54 26 start_date = models.DateTimeField(db_index=True,
bgneal@54 27 help_text='Start date for when the bulletin will be active.',)
bgneal@54 28 end_date = models.DateTimeField(blank=True, null=True, db_index=True,
bgneal@54 29 help_text='End date for the bulletin. Leave blank to keep it open-ended.')
bgneal@54 30 is_enabled = models.BooleanField(default=True, db_index=True,
bgneal@54 31 help_text='Check to allow the bulletin to be viewed on the site.')
gremmie@1 32
bgneal@54 33 objects = BulletinManager()
gremmie@1 34
bgneal@54 35 class Meta:
bgneal@54 36 ordering = ('-start_date', )
gremmie@1 37
bgneal@54 38 def __unicode__(self):
bgneal@54 39 return self.title
bgneal@54 40
bgneal@182 41 def save(self, *args, **kwargs):
bgneal@182 42 super(Bulletin, self).save(*args, **kwargs)
bgneal@54 43 cache.delete('home_bulletins')
bgneal@54 44
bgneal@54 45