1 # -*- coding: utf-8 -*-
 
   2 from django.core.cache import cache
 
   3 from django.db import models
 
   4 from django.utils.translation import ugettext_lazy as _
 
   7 class Chunk(models.Model):
 
   9     A Chunk is a piece of content associated with a unique key that can be inserted into
 
  10     any template with the use of a special template tag.
 
  12     key = models.CharField(
 
  13         _('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)
 
  15     content = models.TextField(_('content'), blank=True)
 
  19         verbose_name = _('chunk')
 
  20         verbose_name_plural = _('chunks')
 
  22     def __unicode__(self):
 
  26         return 'chunk_' + self.key
 
  28     def save(self, *args, **kwargs):
 
  29         ret = super(Chunk, self).save(*args, **kwargs)
 
  30         cache.delete(self.cache_key())
 
  34 class Attachment(models.Model):
 
  35     key = models.CharField(_('key'), help_text=_('A unique name for this attachment'), primary_key=True, max_length=255)
 
  36     attachment = models.FileField(upload_to='chunks/attachment')
 
  40         verbose_name, verbose_name_plural = _('attachment'), _('attachments')
 
  42     def __unicode__(self):