我想覆盖saveas按钮的行为 - 我需要在按下它后将我重定向到对象列表中,而不是直接在新对象中。
所以我需要覆盖ModelForm的标准保存方法并进入请求对象 - 检查是否按下了saveas按钮:
*admin.py
class AirplanesAdmin(admin.ModelAdmin):
form = AirplaneEditForm
forms.py
class AirplaneEditForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request', None)
super(AirplaneEditForm, self).__init__(*args, **kwargs)
def clean(self):
print self.request
return self.cleaned_data
def save(self, force_insert=False, force_update=False, commit=True,):
plane = super(AirplaneEditForm, self).save(commit=False)
print self.request
if commit:
plane.save()
return plane
class Meta:
model = Airplanes
但是在这两个打印请求中都是无...我做错了什么吗?