我有几个ModelAdmin类,我想在保存模型时执行相同的操作,所以我为此创建了mixin对象:
class SaveModelMixin(object):
def save_model(self, request, obj, form, change):
if obj.is_executed and 'is_executed' in obj.changed_data:
obj.date_execution = datetime.date.today()
super(self.__class__, self).save_model(request, obj, form, change)
当我尝试在admin中保存对象时,此方法只是一次又一次地运行,我无法弄清楚原因。
答案 0 :(得分:3)
看起来您的super()
来电不正确,请尝试以下操作:
super(SaveModelMixin, self).save_model(request, obj, form, change)
请参阅此处的说明:How to avoid infinite recursion with super()?
另见: