是否可以将表单用作其他形式的字段?

时间:2011-11-10 02:42:46

标签: django forms django-forms

我有一个我在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

1 个答案:

答案 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)