def save(self):
if self.is_global:
other_global = Project.objects.filter(is_global=True).exists()
if other_global:
#handle the error, eg, raise an exception or send a message
return
super.save()
计划模型
def save(self):
if self.is_global:
other_global = Plan.objects.filter(is_global=True).exists()
if other_global:
#handle the error, eg, raise an exception or send a message
return
if not self.project.is_global:
#handle the error, eg, raise an exception or send a message
return
super.save()
1条答案
按热度按时间d4so4syb1#
您可以覆盖每个模型的save函数以检查之前的"is_global"项
项目模型
计划模型