1 from django.core.cache import cache
2 from django.db import models
3 from django.utils.translation import ugettext_lazy as _
4 from markupfield.fields import MarkupField
5 from fnpdjango.utils.models.translation import add_translatable
8 class Chunk(models.Model):
10 A Chunk is a piece of content associated with a unique key that can be inserted into
11 any template with the use of a special template tag.
13 key = models.CharField(_('key'), help_text=_('A unique name for this chunk of content'), primary_key=True, max_length=255)
14 description = models.CharField(_('description'), blank=True, max_length=255)
18 verbose_name = _('chunk')
19 verbose_name_plural = _('chunks')
21 def __unicode__(self):
25 return 'chunk_' + self.key
27 def save(self, *args, **kwargs):
28 ret = super(Chunk, self).save(*args, **kwargs)
29 cache.delete(self.cache_key())
32 add_translatable(Chunk, {
33 'content': MarkupField(_('content'), blank=True, markup_type='textile_pl',
34 help_text=_('Use <a href="http://txstyle.org/">Textile</a> syntax.')),
38 class Attachment(models.Model):
39 key = models.CharField(_('key'), help_text=_('A unique name for this attachment'), primary_key=True, max_length=255)
40 attachment = models.FileField(upload_to='chunks/attachment')
44 verbose_name, verbose_name_plural = _('attachment'), _('attachments')
46 def __unicode__(self):