I can set the class of a widget with a line like
self.widget = forms.CheckboxSelectMultiple(attrs={'class': 'myclass'})
but this applies myclass to all of the <li> elements, e.g.,
<ul>
<label><li><input type="checkbox" class="myclass">1</li></label>
<label><li><input type="checkbox" class="myclass">2</li></label>
<label><li><input type="checkbox" class="myclass">3</li></label>
</ul>
How can I apply a class to only the <ul> element?
By default you cannot set the attribute on the UL tag. The “easy” thing to do is subclass the CheckboxSelectMultiple to do what you want. Two approaches are:
Construct a custom version of the CheckboxSelectMultiple with a “ulattrs” argument.
or, you could do something a little more hacky…