summaryrefslogtreecommitdiffstats
path: root/feincms/content/image/models.py
blob: 2f1d2c4498b158bbb4f2018045ffc6a4ae1992d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from django.db import models
from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _

class ImageContent(models.Model):
    """
    Create an ImageContent like this:

    Cls.create_content_type(ImageContent, POSITION_CHOICES=(
        ('left', 'Left'),
        ('right', Right'),
        ))
    """

    image = models.ImageField(_('image'), upload_to='imagecontent')

    class Meta:
        abstract = True
        verbose_name = _('image')
        verbose_name_plural = _('images')

    def render(self, **kwargs):
        return render_to_string([
            'content/image/%s.html' % self.position,
            'content/image/default.html',
            ], {'content': self})

    @classmethod
    def handle_kwargs(cls, POSITION_CHOICES=()):
        models.CharField(_('position'), max_length=10, choices=POSITION_CHOICES
            ).contribute_to_class(cls, 'position')