aboutsummaryrefslogtreecommitdiff
path: root/models.py
diff options
context:
space:
mode:
authorAlban Gruin2018-01-19 20:48:58 +0100
committerAlban Gruin2018-01-19 20:50:29 +0100
commit8b0626139036e50396f14cf9ae39b12e2540af85 (patch)
tree3b0105eced154a635b1f03ce90957e986dd0a0f9 /models.py
parent2d5bb761ac83bfa4643006681587db2c5e11f60b (diff)
Préchargement des groupes et des salles lorsqu’on demande la liste des
salles. Réduit le nombre de requêtes à effectuer ainsi que le temps de traitement.
Diffstat (limited to 'models.py')
-rw-r--r--models.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/models.py b/models.py
index 4903b11..ae04fb8 100644
--- a/models.py
+++ b/models.py
@@ -178,7 +178,8 @@ class CourseManager(Manager):
qs = qs.filter(groups__in=Group.objects.get_parents(obj), **criteria) \
.prefetch_related("rooms")
elif isinstance(obj, Room):
- qs = qs.filter(rooms__in=(obj,), **criteria)
+ qs = qs.filter(rooms__in=(obj,), **criteria) \
+ .prefetch_related("groups", "rooms")
else:
raise(TypeError, "obj must be a Group or a Room")