我有一个我在Django中创建的表单:
class someForm(forms.Form):...
在其init函数中接受变量someVariable
:
def __init__(self, someVariable, *args, **kwargs):
我是否可以将someForm用作另一种形式的字段?:
class someOtherForm(forms.Form):
sf = someForm(someVariable=self.someVariable)
...
def __init__(self, someVariable, *args, **kwargs)
self.someVariable = someVariable
答案 0 :(得分:2)
我认为你最好的选择就是扩展原来的形式:
def someForm(forms.Form):
someVariable = ...
...
def __init__(self, someVariable, *args, **kwargs):
self.someVariable = someVariable
def someOtherForm(someForm):
...
def __init__(self, someVariable, *args, **kwargs):
super(SomeOtherForm, self).__init__(someVariable, *args, **kwargs)