Django SessionWizardView ModelMultipleChoiceField issue

122 views Asked by At

I am implementing formtools.wizard.views and on first form i have a ModelMultipleChoiceField when i select an option and move to next step i am able to get selected option but when ever i move to the previous step and when submit the form it gives below exception

if not queryset._prefetch_related_lookups:
AttributeError: 'NoneType' object has no attribute '_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])

NOTE: requirements python 3.7 Django==2.2.7 django-formtools2.2

0

There are 0 answers