Django, ModelChoiceField() and initial value

后端 未结 6 2118
灰色年华
灰色年华 2020-12-04 12:14

I\'m using something like this:

field1 = forms.ModelChoiceField(queryset=...)

How can I make my form show the a value as selected?

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 12:33

    You can just use

     field1 = forms.ModelChoiceField(queryset=..., initial=0) 
    

    to make the first value selected etc. It's more generic way, then the other answer.

提交回复
热议问题