fix: base 对循环引用抛出异常
This commit is contained in:
parent
7bbc9d7fb1
commit
6b181c8890
|
@ -62,13 +62,19 @@ class ParentModel(models.Model):
|
||||||
def init_parent_link(self):
|
def init_parent_link(self):
|
||||||
link = []
|
link = []
|
||||||
if self.parent is not None:
|
if self.parent is not None:
|
||||||
|
if self.parent == self:
|
||||||
|
raise Exception(f'{self.__class__.__name__}-{self.id}-存在循环引用')
|
||||||
link = [self.parent.id] # 一级
|
link = [self.parent.id] # 一级
|
||||||
if self.parent.parent is not None: # 二级
|
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)
|
link.insert(0, self.parent.parent.id)
|
||||||
if self.parent.parent.parent is not None: # 三级
|
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)
|
link.insert(0, self.parent.parent.parent.id)
|
||||||
if self.parent.parent.parent.parent is not None:
|
if self.parent.parent.parent.parent is not None:
|
||||||
raise Exception('最多支持四级')
|
raise Exception(f'{self.__class__.__name__}-{self.id}-最多支持四级')
|
||||||
return link
|
return link
|
||||||
|
|
||||||
def handle_parent(self, is_create:bool):
|
def handle_parent(self, is_create:bool):
|
||||||
|
|
Loading…
Reference in New Issue