How can I add attrs in ModelChoiceField?

290 views
Skip to first unread message

李余通

unread,
Jul 31, 2017, 10:59:12 PM7/31/17
to Django users
Hello,Everyone,
I know charField can use
forms.TextInput(attrs={'class' : 'form-control',
}),
or
forms.Textarea(attrs={'class' : "form-control",
'rows' : 3 ,
})

to set widgets

but ModelChoiceField?
I have no idea,Django telled me "'module' object has no attribute 'ChoiceInput'"
when i use
forms.ChoiceInput
and "__init__() got an unexpected keyword argument 'attrs'" when i use ModelChoiceField


Can you help me?
Thank you very much?

李余通

unread,
Aug 1, 2017, 2:36:46 AM8/1/17
to Django users
Now I know it use forms.Select(),however I add attrs whth class ,but it doesn't work!
Gategory = ModelChoiceField(queryset=GoodsType.objects.all())
widgets = {
'Gategory' : forms.Select(attrs={'class' : "form-control",
}),
}

-->>>
<select id="id_Category" name="Category">\n<option value="" selected="selected">---------</option>\n<option value="1">\u5168\u90e8</option>\n<option value="2">\U0001f436</option>\n</select>



在 2017年8月1日星期二 UTC+8上午10:59:12,李余通写道:
Reply all
Reply to author
Forward
0 new messages