aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Gruin2017-11-26 13:27:40 +0100
committerAlban Gruin2017-11-26 13:27:40 +0100
commit34ba9c926cfd0725ebd2905e9c71823fd272dad2 (patch)
tree8d29a420ed8be07441d212d042907e227b45b798
parent630bebd114cdbae7af736e117e2b10b7e9195657 (diff)
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
-rw-r--r--models.py2
-rw-r--r--views.py2
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})