2

我有以下 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

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

4

1 回答 1

5

MultipleChoiceField需要choices而不是queryset

ModelMultipleChoiceField改为使用

evalTypes = forms.ModelMultipleChoiceField(label="Default Evaluation Forms", widget=forms.SelectMultiple, queryset=None)
于 2013-07-03T19:10:57.647 回答