Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DJANGO: Change field size of ModelMultipleChoiceField?

I was wondering how one changes the size of a ModelMultipleChoiceField? I've only seen examples of changing a CharField into a Textarea... Is this possible?

Models.PY

class FilterForm(forms.Form):
    Person = forms.ModelMultipleChoiceField(required=False, queryset=Person.objects.all(), attrs={'cols': 50, 'rows': 10})
like image 606
thedeepfield Avatar asked Sep 18 '25 18:09

thedeepfield


1 Answers

Override the form's __init__ method and add:

self.fields['Person'].widget.attrs['size']='10'
like image 82
greg Avatar answered Sep 21 '25 10:09

greg