Select "class" attributes are not updated

59 views
Skip to first unread message

matteo gassend

unread,
Aug 8, 2018, 9:47:31 AM8/8/18
to Django users
Hello everyone,

I am trying to personalize my select fields in a django modelform, however the changes are not reflected when I try to render the field. Anyone else ever had this problem?

        self.fields["prodotti_var"].widget.attrs.update({"class" : "form-control m-bootstrap-select m_selectpicker", "data-live-search" : "true"})


Can you help me?






Luis Polanco

unread,
Aug 8, 2018, 12:40:32 PM8/8/18
to Django users
Hi

If you are only updating the class attribute you can do a direct assignment to the class attribute on the dictionary like:

self.fields['attendant_authority'].widget.attrs['class'] = 'select_autoridad'
self.fields["prodotti_var"].widget.attrs["class"] = "form-control m-bootstrap-select m_selectpicker"
Reply all
Reply to author
Forward
0 new messages