|
|
|
@ -18,7 +18,8 @@ class BaseModel(models.Model): |
|
|
|
def save(self, *args, **kwargs): |
|
|
|
def save(self, *args, **kwargs): |
|
|
|
if self.related_user is None: |
|
|
|
if self.related_user is None: |
|
|
|
self.related_user = self.find_related_user() |
|
|
|
self.related_user = self.find_related_user() |
|
|
|
self.update_data_access_list() |
|
|
|
if self._state.adding: |
|
|
|
|
|
|
|
self.update_data_access_list() |
|
|
|
super().save(*args, **kwargs) |
|
|
|
super().save(*args, **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
def get_store_id(self): |
|
|
|
def get_store_id(self): |
|
|
|
@ -37,6 +38,13 @@ class BaseModel(models.Model): |
|
|
|
for data_access in data_accesses: |
|
|
|
for data_access in data_accesses: |
|
|
|
self.add_data_access_relation(data_access) |
|
|
|
self.add_data_access_relation(data_access) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# add data_access to children who might not had the relationship |
|
|
|
|
|
|
|
# if data_accesses: |
|
|
|
|
|
|
|
# for child in self.get_children_by_model(): |
|
|
|
|
|
|
|
# if len(child.data_access_ids) == 0: |
|
|
|
|
|
|
|
# for data_access in data_accesses: |
|
|
|
|
|
|
|
# self.add_data_access_relation(data_access) |
|
|
|
|
|
|
|
|
|
|
|
def add_data_access_relation(self, data_access): |
|
|
|
def add_data_access_relation(self, data_access): |
|
|
|
str_id = str(data_access.id) |
|
|
|
str_id = str(data_access.id) |
|
|
|
if str_id not in self.data_access_ids: |
|
|
|
if str_id not in self.data_access_ids: |
|
|
|
@ -57,7 +65,6 @@ class BaseModel(models.Model): |
|
|
|
for child in children: |
|
|
|
for child in children: |
|
|
|
if (child.one_to_many or child.one_to_one) and child.auto_created: |
|
|
|
if (child.one_to_many or child.one_to_one) and child.auto_created: |
|
|
|
model_name = child.related_model.__name__ |
|
|
|
model_name = child.related_model.__name__ |
|
|
|
# print(f'>>> add children for {model_name}') |
|
|
|
|
|
|
|
related_objects[model_name] = getattr(self, child.name).all() |
|
|
|
related_objects[model_name] = getattr(self, child.name).all() |
|
|
|
|
|
|
|
|
|
|
|
return related_objects |
|
|
|
return related_objects |
|
|
|
|