set userrealtion & organization to list of their childs - BaseVewSet

This commit is contained in:
2025-10-27 16:23:34 +03:30
parent 0af53bddb8
commit db97d0102a
3 changed files with 28 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
import typing
from apps.authentication.models import Organization
@@ -15,3 +16,15 @@ def get_users_of_organization(org: Organization) -> typing.Any:
} for rel in user_relations]
return users_list
def get_all_org_child(org: Organization = None) -> typing.Any:
"""
get all child of an organization
"""
descendants = []
children = org.parents.all()
for child in children:
descendants.append(child)
descendants.extend(get_all_org_child(child))
return descendants