1 from django.core.cache import cache
2 from django.db import models
3 from django.utils.translation import ugettext_lazy as _, get_language
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, null=True, max_length=255)
13 content = models.TextField(_('content'), blank=True, null=True)
17 verbose_name = _('chunk')
18 verbose_name_plural = _('chunks')
20 def __unicode__(self):
25 return 'chunk/%s/%s' % (key, get_language())
27 def save(self, *args, **kwargs):
28 ret = super(Chunk, self).save(*args, **kwargs)
29 cache.delete(self.cache_key(self.key))
33 class Attachment(models.Model):
34 key = models.CharField(_('key'), help_text=_('A unique name for this attachment'), primary_key=True, max_length=255)
35 attachment = models.FileField(upload_to='chunks/attachment')
39 verbose_name, verbose_name_plural = _('attachment'), _('attachments')
41 def __unicode__(self):