]> git.0d.be Git - django-panik-combo.git/blobdiff - panikombo/models.py
add minimal/maximal duration filters to sounds cell
[django-panik-combo.git] / panikombo / models.py
index 454678f5da72e716a5a00dcb1f63d398139a358e..178ade1cd438064a0ef8fdbeeb8c629b054a468f 100644 (file)
@@ -231,6 +231,12 @@ 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)
+    minimal_duration = models.PositiveIntegerField(
+            _('Minimal duration (in minutes)'),
+            default=None, blank=True, null=True)
+    maximal_duration = models.PositiveIntegerField(
+            _('Maximal duration (in minutes)'),
+            default=None, blank=True, null=True)
     count = models.PositiveSmallIntegerField(_('Count'), default=20)
     sort_order = models.CharField(_('Sort order'), default='-creation_timestamp',
             max_length=30,
@@ -255,6 +261,10 @@ class SoundsCell(CellBase):
             soundfiles = soundfiles.filter(got_focus__isnull=False)
         if self.sound_format:
             soundfiles = soundfiles.filter(format_id=self.sound_format_id)
+        if self.minimal_duration:
+            soundfiles = soundfiles.filter(duration__gte=self.minimal_duration * 60)
+        if self.maximal_duration:
+            soundfiles = soundfiles.filter(duration__lte=self.maximal_duration * 60)
         soundfiles = soundfiles.select_related().extra(
                     select={'first_diffusion': 'emissions_diffusion.datetime', },
                     select_params=(False, True),