Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个带有布尔参数的内联:first. 我怎样才能编辑save方法,只保存那些内联first = False?
first
save
first = False
可能最好的方法是在模型本身中编辑保存功能:
def save(self, *args, **kwargs): if not self.first: super(My_Model, self).save(*args,**kwargs)
当然,将 My_Model 替换为您的模型名称。这将覆盖默认保存功能,使其仅在 first == False 时运行。