From 15d2faf8e15a036dff9b92433573daa43561ad14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Sat, 8 Apr 2017 13:01:05 +0200 Subject: [PATCH] Fewer requests on spectacles and participants list views --- bda/views.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bda/views.py b/bda/views.py index f99dce26..a3b28af3 100644 --- a/bda/views.py +++ b/bda/views.py @@ -622,7 +622,10 @@ def revente_shotgun(request, tirage_id): def spectacle(request, tirage_id, spectacle_id): tirage = get_object_or_404(Tirage, id=tirage_id) spectacle = get_object_or_404(Spectacle, id=spectacle_id, tirage=tirage) - attributions = spectacle.attribues.all() + attributions = ( + spectacle.attribues + .select_related('participant', 'participant__user') + ) participants = {} for attrib in attributions: participant = attrib.participant @@ -651,7 +654,10 @@ class SpectacleListView(ListView): def get_queryset(self): self.tirage = get_object_or_404(Tirage, id=self.kwargs['tirage_id']) - categories = self.tirage.spectacle_set.all() + categories = ( + self.tirage.spectacle_set + .select_related('location') + ) return categories def get_context_data(self, **kwargs):