misc: distinct active and available tracks in artist view
authorFrédéric Péters <fpeters@0d.be>
Sat, 18 Jul 2020 14:12:10 +0000 (16:12 +0200)
committerFrédéric Péters <fpeters@0d.be>
Sat, 18 Jul 2020 14:12:10 +0000 (16:12 +0200)
nonstop/models.py
nonstop/templates/nonstop/artist_detail.html

index 7563104..591a415 100644 (file)
@@ -43,6 +43,12 @@ class Artist(models.Model):
         return SomaLogLine.objects.filter(filepath__track__artist=self
                 ).exclude(on_air=False).order_by('-play_timestamp')
 
+    def active_tracks(self):
+        return self.track_set.filter(nonstop_zones__isnull=False).distinct().order_by('title')
+
+    def available_tracks(self):
+        return self.track_set.filter(nonstop_zones__isnull=True).order_by('title')
+
 
 class Album(models.Model):
     name = models.CharField(_('Name'), max_length=255)
index 50174f0..3738b73 100644 (file)
 </ul>
 </div>
 
+<div class="section">
+<h3>{% trans "Active tracks" %}</h3>
+
+<ul>
+{% for track in object.active_tracks %}
+<li><a href="{{ track.get_absolute_url }}" class="tracktitle">{{ track.title }}</a>
+        ({% for zone in track.nonstop_zones.all %}{{zone}}{% if not forloop.last %}, {% endif %}{% endfor %})
+</li>
+{% empty %}
+<li><i>{% trans "(none)" %}</i></li>
+{% endfor %}
+</ul>
+</div>
+
+
 <div class="section">
 <h3>{% trans "Available tracks" %}</h3>
 
 <ul>
-{% for track in object.track_set.all %}
+{% for track in object.available_tracks %}
 <li><a href="{{ track.get_absolute_url }}" class="tracktitle">{{ track.title }}</a></li>
+{% empty %}
+<li><i>{% trans "(none)" %}</i></li>
 {% endfor %}
 </ul>
 </div>