表单的动态ChoiceField
创建并初始化动态ChoiceFiled的方法:
class ViewListForm(forms.Form): UIViewId = forms.ChoiceField() def __init__(self,UIViewList,*args, **kwargs): super(ViewListForm, self).__init__(*args, **kwargs) self.fields['UIViewId'] = forms.ChoiceField(choices=[(UIView["Id"], UIView["Name"]) for UIView in UIViewList])
浙公网安备 33010602011771号