refactor(access): add to models a get_organization function

!13
This commit is contained in:
2024-05-29 09:39:55 +09:30
parent a9ea173e74
commit dd0eaae6b3
2 changed files with 14 additions and 9 deletions

View File

@ -24,17 +24,11 @@ class OrganizationMixin():
self.get_object()
if 'access.models.Organization' in str(type(self.get_object())):
id = self.get_object().get_organization().id
id = self.get_object().id
if self.get_object().is_global:
else:
id = self.get_object().organization.id
if self.get_object().is_global:
id = 0
id = 0
except AttributeError:

View File

@ -43,6 +43,10 @@ class Organization(SaveHistory):
modified = AutoLastModifiedField()
def get_organization(self):
return self
class TenancyObject(models.Model):
class Meta:
@ -60,6 +64,9 @@ class TenancyObject(models.Model):
blank = False
)
def get_organization(self) -> Organization:
return self.organization
class Team(Group, TenancyObject, SaveHistory):
class Meta:
@ -140,6 +147,10 @@ class TeamUsers(SaveHistory):
user.groups.remove(group)
def get_organization(self) -> Organization:
return self.team.organization
def save(self, *args, **kwargs):
""" Save Team