diff --git a/apps/utils/models.py b/apps/utils/models.py index 0c83f1a2..4add5eb4 100755 --- a/apps/utils/models.py +++ b/apps/utils/models.py @@ -62,13 +62,19 @@ class ParentModel(models.Model): def init_parent_link(self): link = [] if self.parent is not None: + if self.parent == self: + raise Exception(f'{self.__class__.__name__}-{self.id}-存在循环引用') link = [self.parent.id] # 一级 if self.parent.parent is not None: # 二级 + if self.parent.parent == self: + raise Exception(f'{self.__class__.__name__}-{self.id}-存在循环引用') link.insert(0, self.parent.parent.id) if self.parent.parent.parent is not None: # 三级 + if self.parent.parent.parent == self: + raise Exception(f'{self.__class__.__name__}-{self.id}-存在循环引用') link.insert(0, self.parent.parent.parent.id) if self.parent.parent.parent.parent is not None: - raise Exception('最多支持四级') + raise Exception(f'{self.__class__.__name__}-{self.id}-最多支持四级') return link def handle_parent(self, is_create:bool):