diff options
author | Alban Gruin | 2017-11-18 17:14:26 +0100 |
---|---|---|
committer | Alban Gruin | 2017-11-27 12:11:31 +0100 |
commit | 3148aaf7c43866bd672d54ac54a0e70bc71f1020 (patch) | |
tree | 2df717399a226527cd6e95febae7d754299d4a8e /models.py | |
parent | 1046a9ea68d9a29dc929eb88581e50a0704a5142 (diff) |
Mise en commun du traitement des données avant rendu de l’emploi du temps
Diffstat (limited to 'models.py')
-rw-r--r-- | models.py | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -157,10 +157,15 @@ class Room(models.Model): 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").prefetch_related("rooms") + def get_courses(self, obj, **criteria): + qs = self.get_queryset() + if isinstance(obj, Group): + 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) + + return qs.order_by("begin") def get_weeks(self, **criteria): return self.get_queryset() \ |