本文介绍了从数据库值填充Django ChoiceField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用ChoiceField在数据库中创建值下拉列表时遇到问题。以下是代码片段
I am having problems using a ChoiceField to create a drop down list of values in the database. Here is the snippet of code
from django import forms from testplatform.models import ServiceOffering class ContactForm(forms.Form): subject = forms.ChoiceField(queryset=ServiceOffering.objects.all()) #subject = forms.ModelMultipleChoiceField(queryset=ServiceOffering.objects.all())#subject ....行工作,但是当我使用行ChoiceField(queryset ....)我得到以下错误。
The #subject.... line works, but when I use the line ChoiceField(queryset....) I get the following error.
__init__() got an unexpected keyword argument 'queryset'任何想法?
推荐答案ChoiceField 没有查询器。您正在寻找 ModelChoiceField
ChoiceField doesn't have a queryset. You're looking for ModelChoiceField
更多推荐
从数据库值填充Django ChoiceField
发布评论