make it possible to filter newsitems by category
authorFrédéric Péters <fpeters@0d.be>
Sun, 31 May 2015 11:29:48 +0000 (13:29 +0200)
committerFrédéric Péters <fpeters@0d.be>
Sun, 31 May 2015 11:29:48 +0000 (13:29 +0200)
panikombo/forms.py
panikombo/migrations/0007_newsitemautoselectioncell_category.py [new file with mode: 0644]
panikombo/models.py

index d7a20a6..eae28b4 100644 (file)
@@ -58,7 +58,7 @@ class EpisodeAutoSelectionCellForm(forms.ModelForm):
 class NewsItemAutoSelectionCellForm(forms.ModelForm):
     class Meta:
         model = NewsItemAutoSelectionCell
-        fields = ('title', 'tags', 'future')
+        fields = ('title', 'tags', 'category', 'future')
         widgets = {'tags': TagWidget()}
 
 
diff --git a/panikombo/migrations/0007_newsitemautoselectioncell_category.py b/panikombo/migrations/0007_newsitemautoselectioncell_category.py
new file mode 100644 (file)
index 0000000..99db4c7
--- /dev/null
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('emissions', '0004_focus_page'),
+        ('panikombo', '0006_itemtopik'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='newsitemautoselectioncell',
+            name='category',
+            field=models.ForeignKey(verbose_name='Category', blank=True, to='emissions.NewsCategory', null=True),
+            preserve_default=True,
+        ),
+    ]
index 102a5ed..57848f5 100644 (file)
@@ -126,6 +126,8 @@ class NewsItemAutoSelectionCell(CellBase):
     title = models.CharField(_('Title'), max_length=50, blank=True)
     tags = TaggableManager(_('Tags'), blank=True)
     future = models.BooleanField(_('Future Events Only'), default=True)
+    category = models.ForeignKey('emissions.NewsCategory',
+            verbose_name=_('Category'), null=True, blank=True)
 
     class Meta:
         verbose_name = _('Automatic Newsitem Selection')
@@ -136,6 +138,8 @@ class NewsItemAutoSelectionCell(CellBase):
             newsitems_queryset = newsitems_queryset.filter(tags__in=self.tags.all())
         if self.future:
             newsitems_queryset = newsitems_queryset.filter(event_date__gte=date.today())
+        if self.category:
+            newsitems_queryset = newsitems_queryset.filter(category=self.category)
         return newsitems_queryset
 
     def render(self, context):