From 801d26cb4a53adda563a06f4d7c21ed311262e56 Mon Sep 17 00:00:00 2001 From: Olivier DOSSMANN Date: Sat, 3 Feb 2018 20:11:14 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20de=20l'affichage=20de=20la?= =?UTF-8?q?=20page=20d'accueil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- collection/games/views.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/collection/games/views.py b/collection/games/views.py index 5d5a063..9e30fdb 100644 --- a/collection/games/views.py +++ b/collection/games/views.py @@ -1,12 +1,13 @@ from django.db.models import Q from django.views.generic import ListView from rest_framework import viewsets -from .serializers import ( - GameSerializer, - GameTimelineSerializer, - PlatformSerializer -) -from .models import Game, Platform, Timeline + +from .models import Game +from .models import Platform +from .models import Timeline +from .serializers import GameSerializer +from .serializers import GameTimelineSerializer +from .serializers import PlatformSerializer class PlatformViewSet(viewsets.ModelViewSet): @@ -67,9 +68,8 @@ class GameList(ListView): model = Game context_object_name = 'non_excluded_games' template_name = 'games/index.html' - queryset = Game.objects.filter( - ~Q(status=Game.EXCLUDED) & - Q(wish=False)).order_by('name') + queryset = Game.objects.filter(~Q(status=Game.EXCLUDED) & Q( + wish=False)).order_by('name').prefetch_related('collection') def get_context_data(self, **kwargs): """ @@ -78,9 +78,8 @@ class GameList(ListView): """ context = super(GameList, self).get_context_data(**kwargs) context['playing_games'] = Game.objects.filter( - playing=True).order_by('name') + playing=True).order_by('name').prefetch_related('collection') context['last_timelines'] = Timeline.objects.filter( - ~Q(item__status=Game.EXCLUDED) - ).order_by( - '-date')[:5] + ~Q(item__status=Game.EXCLUDED)).order_by( + '-date')[:5].prefetch_related('item__collection') return context