]> git.0d.be Git - django-panik-combo.git/commitdiff
add tags selection to sounds cell
authorFrédéric Péters <fpeters@0d.be>
Thu, 26 Nov 2020 12:15:26 +0000 (13:15 +0100)
committerFrédéric Péters <fpeters@0d.be>
Thu, 26 Nov 2020 12:15:26 +0000 (13:15 +0100)
panikombo/migrations/0021_soundscell_tags.py [new file with mode: 0644]
panikombo/models.py

diff --git a/panikombo/migrations/0021_soundscell_tags.py b/panikombo/migrations/0021_soundscell_tags.py
new file mode 100644 (file)
index 0000000..45e83e9
--- /dev/null
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.29 on 2020-11-26 12:52
+from __future__ import unicode_literals
+
+from django.db import migrations
+import taggit.managers
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('taggit', '0003_taggeditem_add_unique_index'),
+        ('panikombo', '0020_auto_20201122_2005'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='soundscell',
+            name='tags',
+            field=taggit.managers.TaggableManager(blank=True, help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags'),
+        ),
+    ]
index 178ade1cd438064a0ef8fdbeeb8c629b054a468f..58e728aa42e38ba928004fb35ca5bd4a29a00975 100644 (file)
@@ -231,6 +231,7 @@ class SoundsCell(CellBase):
     limit_to_focus = models.BooleanField(_('Limit to focused elements'), default=False)
     sound_format = models.ForeignKey('emissions.Format',
             verbose_name=_('Limit to format'), null=True, blank=True)
+    tags = TaggableManager(_('Tags'), blank=True)
     minimal_duration = models.PositiveIntegerField(
             _('Minimal duration (in minutes)'),
             default=None, blank=True, null=True)
@@ -252,6 +253,11 @@ class SoundsCell(CellBase):
     class Meta:
         verbose_name = _('Sounds')
 
+    def get_default_form_fields(self):
+        fields = super().get_default_form_fields()
+        fields.insert(fields.index('minimal_duration'), 'tags')
+        return fields
+
     def get_cell_extra_context(self, context):
         soundfiles = SoundFile.objects.prefetch_related('episode__emission__categories')
         soundfiles = soundfiles.filter(podcastable=True)
@@ -265,6 +271,8 @@ class SoundsCell(CellBase):
             soundfiles = soundfiles.filter(duration__gte=self.minimal_duration * 60)
         if self.maximal_duration:
             soundfiles = soundfiles.filter(duration__lte=self.maximal_duration * 60)
+        if self.tags.exists():
+            soundfiles = soundfiles.filter(episode__tags__in=self.tags.all())
         soundfiles = soundfiles.select_related().extra(
                     select={'first_diffusion': 'emissions_diffusion.datetime', },
                     select_params=(False, True),