Commit 226902c3 authored by fred's avatar fred

order episodes by first diffusion date

parent 79158cc0
......@@ -14,7 +14,7 @@
<ul>
{% for episode in episodes %}
<li><a href="{{ episode.slug }}/">{{ episode.title }}</a></li>
<li>{{ episode.first_diffusion }} <a href="{{ episode.slug }}/">{{ episode.title }}</a></li>
{% endfor %}
</ul>
......
......@@ -24,7 +24,18 @@ class EmissionDetailView(DetailView):
def get_context_data(self, **kwargs):
context = super(EmissionDetailView, self).get_context_data(**kwargs)
context['episodes'] = Episode.objects.filter(emission=self.object.id)
#context['episodes'] = Episode.objects.filter(emission=self.object.id)
context['episodes'] = Episode.objects.raw('''
SELECT emissions_episode.*,
datetime AS first_diffusion
FROM emissions_episode, emissions_diffusion
WHERE emissions_episode.id == emissions_diffusion.episode_id
AND emissions_episode.emission_id = %s
AND datetime = (SELECT MIN(datetime)
FROM emissions_diffusion
WHERE episode_id = emissions_episode.id)
ORDER BY first_diffusion DESC''',
[self.object.id])
return context
......@@ -76,4 +87,3 @@ class EpisodeUpdateView(UpdateView):
class EpisodeDeleteView(DeleteView):
model = Episode
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment