我有一个这样的 Django ModelForm:
class ContactPhoneForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(ContactPhoneForm, self).__init__(*args, **kwargs)
#....
...以及我尝试获取相应表单集的视图:
ContactPhoneFormSet = modelformset_factory(ContactPhone,
ContactPhoneForm,
extra=1,
can_delete = True)
现在,我想将一个附加参数传递给__init__
表单的方法:
class ContactPhoneForm(forms.ModelForm):
def __init__(self, contact_id, *args, **kwargs):
self.contact_id = contact_id
super(ContactPhoneForm, self).__init__(*args, **kwargs)
#....
我试图根据这篇文章重写我的观点:
ContactPhoneFormSet = modelformset_factory(ContactPhone,
wraps(ContactPhoneForm)(partial(ContactPhoneForm, contact_id=contact_id)),
extra=1,
can_delete = True)
但我最终得到了TypeError: the first argument must be callable
错误。对此有什么帮助吗?