我有以下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
问题是,当加载页面时,唯一出现的是空选择框。这很奇怪,因为我清楚地证明了queryset正在被正确填充。我能错过什么?
答案 0 :(得分:4)
MultipleChoiceField
需要choices
而非queryset
evalTypes = forms.ModelMultipleChoiceField(label="Default Evaluation Forms", widget=forms.SelectMultiple, queryset=None)