I want to override the bahaviour of saveas button - i need after pushing it to redirecrt me not in list of objects, but in a new object directly.
So i need to override the standart save method of ModelForm and get in there the request object - to check if saveas button was pressed:
*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
But in both prints request is None... Did I do something wrong ?