Reputation: 93
I am trying to set a bootstrap-select class to my choice field. However, I am getting a 'TypeError: init() got an unexpected keyword argument 'attrs''.
class constraintListForm1(forms.Form):
region = forms.ChoiceField(choices=REGION, required=True)
operator = forms.ChoiceField(choices=OPERATOR, required=True )
class META:
model = constraintListModel1
widgets = {
'region': forms.ChoiceField(attrs={'class' : 'bootstrap-select'}),
}
Upvotes: 5
Views: 8375
Reputation: 1930
You set Meta.widgets
, so you should set a widget instead of a field:
class Meta:
model = constraintListModel1
widgets = {
'region': forms.Select(attrs={'class': 'bootstrap-select'}),
}
Upvotes: 0
Reputation: 1269
Try this:
widgets = {
'region': forms.ChoiceField(
widget=forms.Select(attrs={'class':'bootstrap-select'})
),
}
Or just use forms.Select()
:
widgets = {
'region': forms.Select(attrs={'class':'bootstrap-select'}),
}
Upvotes: 4