表单的动态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])

 

posted on 2013-04-07 19:01  0x9801  阅读(219)  评论(0)    收藏  举报

导航