Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
53:f882ac8ce255 | 54:e249b5f9d180 |
---|---|
3 """ | 3 """ |
4 | 4 |
5 import datetime | 5 import datetime |
6 from django.db import models | 6 from django.db import models |
7 from django.db.models import Q | 7 from django.db.models import Q |
8 from django.core.cache import cache | |
8 | 9 |
9 | 10 |
10 class BulletinManager(models.Manager): | 11 class BulletinManager(models.Manager): |
11 """Manager for the Bulletin model.""" | 12 """Manager for the Bulletin model.""" |
12 | 13 |
13 def get_current(self): | 14 def get_current(self): |
14 now = datetime.datetime.now() | 15 now = datetime.datetime.now() |
15 return self.filter( | 16 return self.filter( |
16 Q(is_enabled=True), | 17 Q(is_enabled=True), |
17 Q(start_date__lte=now), | 18 Q(start_date__lte=now), |
18 Q(end_date__isnull=True) | Q(end_date__gte=now)) | 19 Q(end_date__isnull=True) | Q(end_date__gte=now)) |
19 | 20 |
20 | 21 |
21 class Bulletin(models.Model): | 22 class Bulletin(models.Model): |
22 """Model to represent site bulletins.""" | 23 """Model to represent site bulletins.""" |
23 title = models.CharField(max_length=200) | 24 title = models.CharField(max_length=200) |
24 text = models.TextField() | 25 text = models.TextField() |
25 start_date = models.DateTimeField(db_index=True, | 26 start_date = models.DateTimeField(db_index=True, |
26 help_text='Start date for when the bulletin will be active.',) | 27 help_text='Start date for when the bulletin will be active.',) |
27 end_date = models.DateTimeField(blank=True, null=True, db_index=True, | 28 end_date = models.DateTimeField(blank=True, null=True, db_index=True, |
28 help_text='End date for the bulletin. Leave blank to keep it open-ended.') | 29 help_text='End date for the bulletin. Leave blank to keep it open-ended.') |
29 is_enabled = models.BooleanField(default=True, db_index=True, | 30 is_enabled = models.BooleanField(default=True, db_index=True, |
30 help_text='Check to allow the bulletin to be viewed on the site.') | 31 help_text='Check to allow the bulletin to be viewed on the site.') |
31 | 32 |
32 objects = BulletinManager() | 33 objects = BulletinManager() |
33 | 34 |
34 def __unicode__(self): | 35 class Meta: |
35 return self.title | 36 ordering = ('-start_date', ) |
36 | 37 |
37 class Meta: | 38 def __unicode__(self): |
38 ordering = ('-start_date', ) | 39 return self.title |
40 | |
41 def save(self, force_insert=False, force_update=False): | |
42 super(Bulletin, self).save(force_insert, force_update) | |
43 cache.delete('home_bulletins') | |
44 | |
45 |