Skip to content
Snippets Groups Projects
Verified Commit f62686d7 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Implement child_groups_recursive

parent ac78c91c
No related branches found
No related tags found
1 merge request!852Resolve "Add recursive helper methods for Group"
......@@ -506,6 +506,17 @@ class Group(SchoolTermRelatedExtensibleModel):
def child_groups_recursive(self) -> CTEQuerySet:
"""Get all child groups recursively."""
def _make_cte(cte):
Through = self.child_groups.through
return (
Through.objects.values("from_group_id")
.filter(to_group=self)
.union(cte.join(Through, to_group=cte.col.from_group_id), all=True)
)
cte = With.recursive(_make_cte)
return cte.join(Group, id=cte.col.from_group_id).with_cte(cte)
def __str__(self) -> str:
if self.school_term:
return f"{self.name} ({self.short_name}) ({self.school_term})"
......
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