Reputation: 30946
How exactly do I add css to a forms.ModelMultipleChoiceField
I tried to pass in attrs={'class' : 'foo'}
But it's failing saying "__init__() got an unexpected keyword argument 'attrs'"
my_list = forms.ModelMultipleChoiceField(label='List', required=False, queryset=[])
Upvotes: 1
Views: 2023
Reputation: 118528
It's the widget that needs the attrs, not the form field.
my_list = forms.ModelMultipleChoiceField(
label='List',
required=False,
queryset=[],
widget=SelectMultiple(attrs={'class': 'foobar'}))
Upvotes: 5