]> git.0d.be Git - django-panik-combo.git/commitdiff
add sort order option to sounds cell
authorFrédéric Péters <fpeters@0d.be>
Sat, 21 Nov 2020 20:00:04 +0000 (21:00 +0100)
committerFrédéric Péters <fpeters@0d.be>
Sat, 21 Nov 2020 20:00:04 +0000 (21:00 +0100)
panikombo/migrations/0018_soundscell_sort_order.py [new file with mode: 0644]
panikombo/models.py

diff --git a/panikombo/migrations/0018_soundscell_sort_order.py b/panikombo/migrations/0018_soundscell_sort_order.py
new file mode 100644 (file)
index 0000000..a7a1456
--- /dev/null
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.29 on 2020-11-21 20:58
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('panikombo', '0017_soundscell_title'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='soundscell',
+            name='sort_order',
+            field=models.CharField(choices=[('-creation_timestamp', 'Reverse chronological (creation)'), ('-first_diffusion', 'Reverse chronological (diffusion)'), ('creation_timestamp', 'Chronological (creation)'), ('first_diffusion', 'Chronological (diffusion)'), ('?', 'Random')], default='-creation_timestamp', max_length=30, verbose_name='Sort order'),
+        ),
+    ]
index 26a8d2a8c3c02c0fafd486dd504c724c313953f0..26a8e305d63a0358e82260a7f9cdf0d4cb2a1d0b 100644 (file)
@@ -230,6 +230,16 @@ class SoundsCell(CellBase):
     include_fragments = models.BooleanField(_('Include fragments'), default=True)
     limit_to_focus = models.BooleanField(_('Limit to focused elements'), default=False)
     count = models.PositiveSmallIntegerField(_('Count'), default=20)
+    sort_order = models.CharField(_('Sort order'), default='-creation_timestamp',
+            max_length=30,
+            choices=[
+                ('-creation_timestamp', _('Reverse chronological (creation)')),
+                ('-first_diffusion', _('Reverse chronological (diffusion)')),
+                ('creation_timestamp', _('Chronological (creation)')),
+                ('first_diffusion', _('Chronological (diffusion)')),
+                ('?', _('Random')),
+            ]
+            )
 
     class Meta:
         verbose_name = _('Sounds')
@@ -247,7 +257,7 @@ class SoundsCell(CellBase):
                     where=['''datetime = (SELECT MIN(datetime)
                                             FROM emissions_diffusion
                                         WHERE episode_id = emissions_episode.id)'''],
-                    tables=['emissions_diffusion'],).order_by('-creation_timestamp').distinct()
+                    tables=['emissions_diffusion'],).order_by(self.sort_order).distinct()
         return {
             'include_search_input': self.include_search_input,
             'count': self.count,