add - new vivibility filter by org type & remove city province from device

This commit is contained in:
2025-11-03 10:18:59 +03:30
parent 9fb0292817
commit 5ce107fd3a
6 changed files with 116 additions and 18 deletions

View File

@@ -0,0 +1,24 @@
from apps.core.visibility_registry import VISIBILITY_MAP_BY_ORG_KEY
def apply_visibility_filter_by_org_type(queryset, org):
"""
Dynamically filter queryset based on user's organization type and model.
"""
if not org:
return queryset.none()
model_name = queryset.model.__name__.lower()
if model_name not in VISIBILITY_MAP_BY_ORG_KEY:
return queryset
org_type_key = getattr(org.type, 'key', None)
visibility_field = VISIBILITY_MAP_BY_ORG_KEY[model_name].get(org_type_key)
if visibility_field is None:
return queryset
filter_kwargs = {f"{visibility_field}": org}
return queryset.filter(**filter_kwargs)