]> git.0d.be Git - django-panik-combo.git/commitdiff
add option to limit sounds to a given format
authorFrédéric Péters <fpeters@0d.be>
Sun, 22 Nov 2020 13:08:39 +0000 (14:08 +0100)
committerFrédéric Péters <fpeters@0d.be>
Sun, 22 Nov 2020 13:08:39 +0000 (14:08 +0100)
panikombo/migrations/0019_soundscell_sound_format.py [new file with mode: 0644]
panikombo/models.py

diff --git a/panikombo/migrations/0019_soundscell_sound_format.py b/panikombo/migrations/0019_soundscell_sound_format.py
new file mode 100644 (file)
index 0000000..2530f12
--- /dev/null
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.29 on 2020-11-22 14:02
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('emissions', '0015_auto_20200404_1510'),
+        ('panikombo', '0018_soundscell_sort_order'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='soundscell',
+            name='sound_format',
+            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='emissions.Format', verbose_name='Limit to format'),
+        ),
+    ]
index 26a8e305d63a0358e82260a7f9cdf0d4cb2a1d0b..6ad7c8f57132a0c06be51dcd8ea54ec83785e167 100644 (file)
@@ -229,6 +229,8 @@ class SoundsCell(CellBase):
     include_search_input = models.BooleanField(_('Include search input'), default=True)
     include_fragments = models.BooleanField(_('Include fragments'), default=True)
     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)
     count = models.PositiveSmallIntegerField(_('Count'), default=20)
     sort_order = models.CharField(_('Sort order'), default='-creation_timestamp',
             max_length=30,
@@ -251,6 +253,8 @@ class SoundsCell(CellBase):
             soundfiles = soundfiles.filter(fragment=False)
         if self.limit_to_focus:
             soundfiles = soundfiles.filter(got_focus__isnull=False)
+        if self.sound_format:
+            soundfiles = soundfiles.filter(format_id=self.sound_format_id)
         soundfiles = soundfiles.select_related().extra(
                     select={'first_diffusion': 'emissions_diffusion.datetime', },
                     select_params=(False, True),