Store year and party as a tuple. v2
authorDavid ‘Bombe’ Roden <bombe@demoscenemusic.org>
Fri, 10 May 2013 23:31:59 +0000 (01:31 +0200)
committerDavid ‘Bombe’ Roden <bombe@demoscenemusic.org>
Fri, 10 May 2013 23:31:59 +0000 (01:31 +0200)
data/views.py
templates/home.html

index bb3b52c..3a08a7a 100644 (file)
@@ -7,13 +7,13 @@ from DemosceneMusic.data.models import Track
 
 def home(request):
        tracks = Track.objects.all().annotate().order_by('releases__party', 'trackartist__artist__name', 'name', 'remix')
-       partyCompoTracks = defaultdict(lambda: defaultdict(list))
+       partyYearCompoTracks = defaultdict(lambda: defaultdict(list))
        for track in tracks:
                for release in track.releases.all():
-                       partyCompoTracks[release.party][release.compo].append(track)
-       for party, compoTracks in partyCompoTracks.iteritems():
-               partyCompoTracks[party] = dict(compoTracks)
-       return render_to_response('templates/home.html', {'partyTracks': dict(partyCompoTracks)})
+                       partyYearCompoTracks[(release.party, release.year)][release.compo].append(track)
+       for partyYear, compoTracks in partyYearCompoTracks.iteritems():
+               partyYearCompoTracks[partyYear] = dict(compoTracks)
+       return render_to_response('templates/home.html', {'partyTracks': dict(partyYearCompoTracks)})
 
 def track(request, trackId):
        return HttpResponse('Track: %s' % trackId)
index 3353229..7f0d87e 100644 (file)
@@ -8,7 +8,7 @@
 
 {% for party, compoTracks in partyTracks.items %}
        <div>
-               <h2>{{ party }}</h2>
+               <h2>{{ party.0 }} {{ party.1 }}</h2>
                {% for compo, tracks in compoTracks.items %}
                        <h3>{{ compo }}</h3>
                        <ul>