1 from django.core.cache import cache
2 from django.db import models
3 from django.utils.translation import ugettext_lazy as _
6 class Chunk(models.Model):
8 A Chunk is a piece of content associated with a unique key that can be inserted into
9 any template with the use of a special template tag.
11 key = models.CharField(_('key'), help_text=_('A unique name for this chunk of content'), primary_key=True, max_length=255)
12 description = models.CharField(_('description'), blank=True, max_length=255)
13 content = models.TextField(_('content'), blank=True)
17 verbose_name = _('chunk')
18 verbose_name_plural = _('chunks')
20 def __unicode__(self):
24 return 'chunk_' + self.key
26 def save(self, *args, **kwargs):
27 ret = super(Chunk, self).save(*args, **kwargs)
28 cache.delete(self.cache_key())
32 class Attachment(models.Model):
33 key = models.CharField(_('key'), help_text=_('A unique name for this attachment'), primary_key=True, max_length=255)
34 attachment = models.FileField(upload_to='chunks/attachment')
38 verbose_name, verbose_name_plural = _('attachment'), _('attachments')
40 def __unicode__(self):