Skip to content
Snippets Groups Projects
Verified Commit eceac485 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Rewrite filter_group to select lessons only one time

parent 0ad7e1d0
No related branches found
No related tags found
1 merge request!45Improve handling of child/parent groups
......@@ -127,10 +127,17 @@ class LessonDataQuerySet(models.QuerySet):
def filter_group(self, group: Union[Group, int]):
""" Filter for all lessons a group (class) regularly attends. """
return self.filter(
Q(**{self._period_path + "lesson__groups": group})
| Q(**{self._period_path + "lesson__groups__parent_groups": group})
)
if isinstance(group, int):
group = Group.objects.get(pk=group)
if group.parent_groups:
# Prevent to show lessons multiple times
return self.filter(Q(**{self._period_path + "lesson__groups": group}))
else:
return self.filter(
Q(**{self._period_path + "lesson__groups": group})
| Q(**{self._period_path + "lesson__groups__parent_groups": group})
)
def filter_teacher(self, teacher: Union[Person, int]):
""" Filter for all lessons given by a certain teacher. """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment