【发布时间】:2016-03-13 20:35:13
【问题描述】:
伙计们,
我需要实现一个可能会因变量而略有不同的表单。我的子类 ModelForms 的类看起来像这样
class ConstantVwModelForm(forms.ModelForm):
#couple attributes
def __init__(self, hasData, *args, **kwargs):
class Meta:
fields = ('xx', 'yy' ..)
我正在寻找从内部class Meta 访问变量hasData 的最佳方法,就像
class ConstantVwModelForm(forms.ModelForm):
#couple attributes
def __init__(self, hasData, *args, **kwargs):
class Meta:
if hasData:
fields = ('xx', 'yy', ..)
else:
fields = ('hh', ..)
非常感谢任何帮助
【问题讨论】:
标签: python django python-2.7 django-forms inner-classes