1

我正在实施formtools.wizard.views并且在第一个表单上,当我选择一个选项并移至下一步时,我有一个ModelMultipleChoiceField例外

如果不是 queryset._prefetch_related_lookups:
AttributeError: 'NoneType' 对象没有属性 '_prefetch_related_lookups'

# **form 1**
class Form1(forms.Form):
    person = forms.ModelMultipleChoiceField(label=_("Student"), queryset=None, required=False)

# **form 2**
class Form2(forms.Form):
    classification = forms.ChoiceField(label=_("Classification"), choices=classification_appointment)


# **view**
class AddAppointment(SessionWizardView):
    template_name = "appointment/appointment_form_add_using_stepper.html"

    def get(self, request, *args, **kwargs):
        try:
            form = self.get_form()
            if form.prefix == "0":
                form.fields["person"].queryset = Person.objects.filter(user_id=self.request.user.id,
                                                                       classification="student").order_by(
                    'first_name')
return self.render(form)
        except KeyError:
            return super().get(request, *args, **kwargs)
#**url**
path('application_form/', AddAppointment.as_view([Form1, Form2])

注意:要求 python 3.7 Django==2.2.7 django-formtools2.2

4

0 回答 0