From 48f36974e727dd2fcce6b930ff76158345c15c20 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 31 May 2015 15:20:56 +0200 Subject: [PATCH] add topik cell --- panikombo/migrations/0008_topikcell.py | 35 ++++++++++++++++++++++++++ panikombo/models.py | 22 ++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 panikombo/migrations/0008_topikcell.py diff --git a/panikombo/migrations/0008_topikcell.py b/panikombo/migrations/0008_topikcell.py new file mode 100644 index 0000000..e117285 --- /dev/null +++ b/panikombo/migrations/0008_topikcell.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +import ckeditor.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0001_initial'), + ('data', '0009_auto_20150529_2247'), + ('panikombo', '0007_newsitemautoselectioncell_category'), + ] + + operations = [ + migrations.CreateModel( + name='TopikCell', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('placeholder', models.CharField(max_length=20)), + ('order', models.PositiveIntegerField()), + ('slug', models.SlugField(verbose_name='Slug', blank=True)), + ('public', models.BooleanField(default=True, verbose_name='Public')), + ('text', ckeditor.fields.RichTextField(null=True, verbose_name='Text', blank=True)), + ('groups', models.ManyToManyField(to='auth.Group', verbose_name='Groups', blank=True)), + ('page', models.ForeignKey(to='data.Page')), + ('topik', models.ForeignKey(to='panikombo.Topik', null=True)), + ], + options={ + 'verbose_name': 'Topik', + }, + bases=(models.Model,), + ), + ] diff --git a/panikombo/models.py b/panikombo/models.py index 617212a..c587791 100644 --- a/panikombo/models.py +++ b/panikombo/models.py @@ -5,6 +5,7 @@ from django import template from django.db import models from django.utils.translation import ugettext_lazy as _ +from ckeditor.fields import RichTextField from taggit.managers import TaggableManager from combo.data.models import CellBase @@ -172,6 +173,11 @@ class Topik(models.Model): got_focus = models.DateTimeField(default=None, null=True, blank=True) has_focus = models.BooleanField(default=False) + def __unicode__(self): + if not self.page: + return super(Topik, self).__unicode__() + return unicode(self.page) + class ItemTopik(models.Model): newsitem = models.ForeignKey('emissions.NewsItem', verbose_name=_('News Item'), @@ -180,3 +186,19 @@ class ItemTopik(models.Model): null=True, blank=True) topik = models.ForeignKey('Topik', verbose_name='Topik', null=True, blank=True) + + +@register_cell_class +class TopikCell(CellBase): + topik = models.ForeignKey(Topik, null=True) + text = RichTextField(_('Text'), blank=True, null=True) + + template_name = 'panikombo/topik-cell.html' + + class Meta: + verbose_name = _('Topik') + + def get_additional_label(self): + if not self.topik: + return '' + return self.topik.page.title -- 2.39.2