From fe40facfa2d50165097ac7fbd9741430700599be Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 7 Jun 2024 09:49:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20base=20=E5=AF=B9=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E5=BC=95=E7=94=A8=E6=8A=9B=E5=87=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/utils/models.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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):