0

フォームにフィールドがあります

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 動的に初期化するときに使用する必要があるため、ウィジェットを使用できません。これを行うにはどうすればよいですか。form.fields['myForm'].widgets.choices =

4

1 に答える 1

3

Pythonは素晴らしいです。

form.fields['myForm'].widgets.choices =実際には私の擬似コードであり、そのように機能しました。

于 2011-11-18T07:04:58.530 に答える