I am using a ModelForm and trying to set a css class on a Django forms.RadioSelect widget like
class Meta:
model = models.MyModel
fields = ('rating',)
widgets = {
'rating': forms.RadioSelect(attrs={'class':'star'}),
}
but class='star' does not get rendered in the html.
I also tried using:
def __init__(self, *args, **kwargs):
super(MyModelForm, self).__init__(*args, **kwargs)
self.fields['rating'].widget.attrs['class'] = 'star'
which also did not work. I tried the same thing with forms.Textarea widget and there I was able to get the css class rendered.
Am I doing anything wrong here or does RadioSelect just no support the class attribute (I want the class name applied to all radio inputs)?