I want to use multipleChoiceField, to choice from model
I have model,Template
so ,I did this in forms.py
class WorkerForm(forms.ModelForm):
templates = forms.MultipleChoiceField(
Template.objects.all(), required=False, label='template')
However it shows error
templates = forms.MultipleChoiceField(
TypeError: __init__() takes 1 positional argument but 2 were given
I am checking the document here.
CodePudding user response:
You should use a ModelMultipleChoiceField
[Django-doc], and probably it is better to work with a named parameter:
class WorkerForm(forms.ModelForm):
templates = forms.ModelMultipleChoiceField(
queryset=Template.objects.all(), required=False, label='template'
)