我有以下 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
evalTypes = forms.ModelMultipleChoiceField(label="Default Evaluation Forms", widget=forms.SelectMultiple, queryset=None)
关于python - Django Form 拒绝在多个选择字段中呈现查询集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17456248/