2011-11-18 78 views
0

我在我的形式Django的動態ChoiceField和驗證錯誤

myFormList = [(u'Select',u'Select')] 
myForm = forms.ChoiceField(choices=myFormList) 

場,我初始化它使用動態

form.fields['myForm'].choices = form.fields['myForm'].choices + anotherMyFormList 

Select a valid choice. ** is not one of the available choices

通常導致驗證錯誤我擺脫這個錯誤

myForm = forms.CharField(widget = forms.Select(choices=myFormList)) 

但因爲我必須使用form.fields['myForm'].choices同時動態初始化我不能用widgets.How做這form.fields['myForm'].widgets.choices =

回答

3

Python是一流的。

form.fields['myForm'].widgets.choices =實際上是我的僞代碼&這樣工作。