Mercurial > public > sg101
diff gpp/bulletins/models.py @ 54:e249b5f9d180
#3, #4: clear caches when saving profile, bulletins, and news. Broke up the stuff on the home page for finer control of caching.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 23 Jun 2009 00:11:00 +0000 |
parents | dbd703f7d63a |
children | 5c889b587416 |
line wrap: on
line diff
--- a/gpp/bulletins/models.py Sun Jun 21 22:41:58 2009 +0000 +++ b/gpp/bulletins/models.py Tue Jun 23 00:11:00 2009 +0000 @@ -5,34 +5,41 @@ import datetime from django.db import models from django.db.models import Q +from django.core.cache import cache class BulletinManager(models.Manager): - """Manager for the Bulletin model.""" + """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)) + 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.') + """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() + objects = BulletinManager() - def __unicode__(self): - return self.title + class Meta: + ordering = ('-start_date', ) - class Meta: - ordering = ('-start_date', ) + def __unicode__(self): + return self.title + + def save(self, force_insert=False, force_update=False): + super(Bulletin, self).save(force_insert, force_update) + cache.delete('home_bulletins') + +