Django ManytoManyField and widgets

djangodjango-formsdjango-widget

I have two models, Product and Category and ManytoMany field in Product.
The Category appear as key on ProductCreate View.

I need to customize the widget and field for Categories.

I checked in Django source Fields and Widgets but I don't see a reference(class) for ManyToMany.

To what type of Field and Widget ManyToMany relationship corresponds(I presume is Charfield as save or SelectField)? Where I can find the code ? (an example to customize field/widget in this case)

Best Answer

A model ManyToManyField is represented as a MultipleChoiceField and the default widget is SelectMultiple But, we can customise it. You can find it in below references.
[1]https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#field-types
[2]https://docs.djangoproject.com/en/dev/ref/forms/widgets/#setting-arguments-for-widgets

Related Topic