[Django]-DJANGO: Change field size of ModelMultipleChoiceField?

1👍

You can change the width and height of the widget by applying CSS to the <select> element that Django creates.

👤Abid A

11👍

Override the form’s __init__ method and add:

self.fields['Person'].widget.attrs['size']='10'
👤greg

5👍

Try this:

from django.forms import widgets
class FilterForm(forms.Form):
    Person = forms.ModelMultipleChoiceField(required=False, queryset=Person.objects.all(), widget=widgets.SelectMultiple(attrs={'size': 20}))
👤Anshik

Leave a comment