diff --git a/app/access/models.py b/app/access/models.py index 4334065aa..526df85ad 100644 --- a/app/access/models.py +++ b/app/access/models.py @@ -143,6 +143,8 @@ class TenancyManager(models.Manager): This manager specifically caters for the multi-tenancy features of Centurion ERP. """ + _app_settings: any = None + def get_queryset(self): """ Fetch the data @@ -179,15 +181,19 @@ def get_queryset(self): if request: - from settings.models.app_settings import AppSettings + if not self._app_settings: - app_settings = AppSettings.objects.prefetch_related('global_organization').get( - owner_organization = None - ) + from settings.models.app_settings import AppSettings + + app_settings = AppSettings.objects.prefetch_related('global_organization').get( + owner_organization = None + ) + + self._app_settings = app_settings - if app_settings.global_organization: + if self._app_settings.global_organization: - user_organizations += [ app_settings.global_organization.id ] + user_organizations += [ self._app_settings.global_organization.id ] # user = request.user._wrapped if hasattr(request.user,'_wrapped') else request.user @@ -196,7 +202,7 @@ def get_queryset(self): if user.is_authenticated: - for team_user in TeamUsers.objects.filter(user=user): + for team_user in TeamUsers.objects.filter(user=user).prefetch_related('team__organization'): if team_user.team.organization.name not in user_organizations: