gpt4 book ai didi

django - 从数据库值填充的Django ChoiceField

转载 作者:行者123 更新时间:2023-12-03 14:33:35 24 4
gpt4 key购买 nike

使用ChoiceField在数据库中创建值的下拉列表时遇到问题。这是代码片段

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 ....)时,出现以下错误。

__init__() got an unexpected keyword argument 'queryset'


有任何想法吗?

最佳答案

ChoiceField没有查询集。您正在寻找ModelChoiceField

关于django - 从数据库值填充的Django ChoiceField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11936470/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com