diff options
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() \ |