From 34ba9c926cfd0725ebd2905e9c71823fd272dad2 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Sun, 26 Nov 2017 13:27:40 +0100 Subject: Optimisation de deux requêtes : – sélection des cours d’un groupe : préchargement des salles – sélection des emplois du temps d’une année : préchargement de l’année --- models.py | 2 +- views.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/models.py b/models.py index cd19259..b260275 100644 --- a/models.py +++ b/models.py @@ -152,7 +152,7 @@ class CourseManager(Manager): def get_courses_for_group(self, group, **criteria): return self.get_queryset() \ .filter(groups__in=Group.objects.get_parents(group), **criteria) \ - .order_by("begin") + .order_by("begin").prefetch_related("rooms") def get_weeks(self, **criteria): return self.get_queryset() \ diff --git a/views.py b/views.py index 1269415..5eb224e 100644 --- a/views.py +++ b/views.py @@ -31,7 +31,7 @@ def index(request): def mention_list(request, year_slug): year = get_object_or_404(Year, slug=year_slug) - timetables = Timetable.objects.order_by("name").filter(year=year) + timetables = Timetable.objects.order_by("name").filter(year=year).select_related("year") return render(request, "index.html", {"year": year, "elements": timetables}) -- cgit v1.2.1