Try this, with class Meta
:
from django.forms.widgets import CheckboxSelectMultiple
from django.forms import ModelMultipleChoiceField,ModelForm
from kunden.models import Kunde, Unternehmenstyp
class KundeEditForm(ModelForm):
class Meta: # model must be in the Meta class
model = Kunde
unternehmenstyp = ModelMultipleChoiceField(widget=CheckboxSelectMultiple,required=True, queryset=Unternehmenstyp.objects.all())
REF: https://docs.djangoproject.com/en/1.5/topics/forms/modelforms/#modelform
You can also use modelform factories if you only need to make a simple override:
from django.views.generic.edit import UpdateView
from django.forms.models import modelform_factory
from kunden.models import Kunde, Unternehmenstyp
class KundeUpdate(UpdateView):
model = Kunde
form_class = modelform_factory(Kunde,
widgets={"unternehmenstyp": CheckboxSelectMultiple })
template_name = 'kunden/kunde_update.html'
success_url = '/'
REF: https://docs.djangoproject.com/en/1.5/topics/forms/modelforms/#modelform-factory-function