gpt4 book ai didi

python - Django Form 拒绝在多个选择字段中呈现查询集

转载 作者:行者123 更新时间:2023-11-28 22:54:57 25 4
gpt4 key购买 nike

我有以下 Django 形式:

class AccountForm(Form):

evalTypes = django_fields.MultipleChoiceField(label="Default Evaluation Forms", widget=django_widgets.SelectMultiple)

def __init__(self, *args, **kwargs):
super(AccountForm, self).__init__(*args, **kwargs)

# GET POSSIBLE LIST OF EVALUATIONS

self.fields["evalTypes"].queryset = CustomForm.objects.filter(author__permissions__name__in=['manager'])

for q in self.fields["evalTypes"].queryset:
print q # THIS PRINTS ALL THE CORRECT VALUES

问题是当页面加载时,唯一出现的是空的选择框。这很奇怪,因为我有明确的证据表明查询集被正确填充。我可能缺少什么?

最佳答案

MultipleChoiceField采用choices 而不是queryset

使用ModelMultipleChoiceField相反

evalTypes = forms.ModelMultipleChoiceField(label="Default Evaluation Forms", widget=forms.SelectMultiple, queryset=None)

关于python - Django Form 拒绝在多个选择字段中呈现查询集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17456248/

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