我有以下根据type
实例动态创建一个字段:
class LVariableForm(ModelForm):
def __init__(self, *args, **kwargs):
super(someObj, self).__init__(*args, **kwargs)
if self.instance:
if self.instance.type == 'bool':
self.fields['data'] = BooleanField()
if self.instance.type == 'date':
self.fields['data'] = DateField()
if self.instance.type == 'float':
self.fields['data'] = DecimalField()
if self.instance.type == 'text':
self.fields['data'] = TextInput()
self.fields['data'].label = self.instance.name
class Meta:
model = LVariable
唯一的问题是创建的元素具有名称data
和 id1_data
<input name="data" id="1_data" dojoType="dijit.form.NumberTextBox">
我怎样才能改变这些?