fix - show org type by binary childs

This commit is contained in:
2025-11-04 11:59:20 +03:30
parent bcc9bac5fc
commit 95921aa8b4
4 changed files with 43 additions and 4 deletions

View File

@@ -207,7 +207,7 @@ class ProvinceViewSet(SoftDeleteMixin, ModelViewSet):
serializer_class = ProvinceSerializer
class OrganizationTypeViewSet(SoftDeleteMixin, ModelViewSet):
class OrganizationTypeViewSet(BaseViewSet, SoftDeleteMixin, ModelViewSet):
""" Crud operations for Organization Type model """ #
queryset = OrganizationType.objects.all()
serializer_class = OrganizationTypeSerializer

View File

@@ -1,6 +1,6 @@
import typing
from apps.authentication.models import Organization
from apps.authentication.models import Organization, OrganizationType
def get_users_of_organization(org: Organization) -> typing.Any:
@@ -28,3 +28,15 @@ def get_all_org_child(org: Organization = None) -> typing.Any:
descendants.append(child)
descendants.extend(get_all_org_child(child))
return descendants
def get_all_org_type_child(org_type: OrganizationType = None) -> typing.Any:
"""
get all child of an organization
"""
descendants = []
children = org_type.children.all()
for child in children:
descendants.append(child)
descendants.extend(get_all_org_type_child(child))
return descendants