I have a model with a ManyToMany relation that I would like to update with a CheckBoxSelectMultiple widget while everything else uses the default generic form, but when I redefi
Here's a mixin that allows you to define a widgets dictionary and still respects the fields
list:
from django.forms.models import modelform_factory
class ModelFormWidgetMixin(object):
def get_form_class(self):
return modelform_factory(self.model, fields=self.fields, widgets=self.widgets)
It can be used with CreateView, UpdateView, etc. For example:
class KundleUpdate(ModelFormWidgetMixin, UpdateView):
model = Kunde
widgets = {
'unternehmenstyp': CheckboxSelectMultiple,
}