我使用django表单向导并在使用任何多项选择时出现此错误。我不知道为什么我会得到它,但我认为这是因为我传递了多个数据,因为它确实可以使用唯一的选择(如radioselect)。
Error binding parameter 0 - probably unsupported type
以下是代码: forms.py
class CustomChoiceField(forms.ModelChoiceField):
def label_from_instance(self, obj):
return mark_safe('<div><p class="companyname" style="%s">My company</p></div>' % (obj.font_css))
class ContactForm1(forms.ModelForm):
choice_box = CustomChoiceField(widget=forms.CheckboxSelectMultiple, queryset=ImageCheckView.objects.all(), empty_label=None)
class Meta:
model = ImageCheckView
fields = ['title', 'choice_box']
def __init__(self, *args, **kwargs):
super(ContactForm1, self).__init__(*args, **kwargs)
self.fields['choice_box'].empty_label = None
views.py
class ContactWizard(SessionWizardView):
def get_template_names(self):
return [TEMPLATES[self.steps.current]]
def get_context_data(self, form, **kwargs):
context = super(ContactWizard, self).get_context_data(form=form, **kwargs)
if self.steps.current == '0':
context.update({'datas': ImageCheckView.objects.all()})
return context
def done(self, form_list, **kwargs):
form_data = process_form_data(form_list)
context = {'form_data': form_data}
return render_to_response('done.html', context)
def process_form_data(form_list):
form_data = [form.cleaned_data for form in form_list]
return form_data
有任何解决此问题的建议吗?
答案 0 :(得分:0)
通过替换
解决了我的问题class CustomChoiceField(forms.ModelChoiceField):
通过
class CustomChoiceField(forms.ModelMultipleChoiceField):
现在,多个复选框字段将通过步骤传递,并在表单向导上正常工作。