I have a problem with formwizard. In step 3 of the wizard I use a filtered
query which depends on choices from step 1 and 2. My wizard works fine when
moving forward, but when a user presses previous, or changes the choices of
step 1 and 2, things go wrong (validation error or filters won't work).
Here is my forms.py:
class BoekForm3(forms.Form):
Activiteit = forms.ModelChoiceField(queryset=Activiteit.objects.all(),
empty_label="(Nothing)")
If I use queryset Activiteit.objects.none() in forms.py the correct fields
in step3 of the wizard show up right, but the step3 always give a
validation error.
If I use queryset Activiteit.object.all() in forms.py the correct
(filtered) fields show up in step3 when going forward, and the form
validates. However when a user presses previous in step4 the filter is
gone, and all choices are available.
I think that the fields are updated moving to step3, but the form isn't. I
have included my views.py below.
class BoekingWizard(SessionWizardView):
def get_template_names(self):
return [TEMPLATES[self.steps.current]]
def get_context_data(self, form, **kwargs):
plaatjes = Activiteitsgroepen.objects.all()
context = super(BoekingWizard, self).get_context_data(form=form,
**kwargs)
if self.steps.current == 'step1':
context.update({'plaatjes': plaatjes})
return context
def get_form(self, step=None, data=None, files=None):
form = super(BoekingWizard, self).get_form(step, data, files)
if step == 'step3':
x = self.get_cleaned_data_for_step('step1') or {}
filter1 = x['Type_activiteit'].Groep
y = self.get_cleaned_data_for_step('step2') or {}
if y['Aantal_personen'] < 76:
filter2 = 'kleinere groepen'
elif y['Aantal_personen'] > 76:
filter2 = 'grotere groepen'
else:
filter2 = 'geen selectie'
reeks = ['1','2','3']
if y['Dagdeel'] in reeks:
filter3 = 'Dagdeel'
elif y['Dagdeel'] == '4':
filter3 = 'Hele dag'
elif y['Dagdeel'] == '5':
filter3 = 'Middag + Avond'
elif y['Dagdeel'] == '6':
filter3 = 'Dag + Avond'
form.fields['Activiteit'].queryset =
Activiteit.objects.filter(Soort__Groep = filter1).filter(Grootte__Naam =
filter2).filter(Dag__Omschrijving = filter3)
return form
I asked a similar question a few days back, but now it is much clearer to
me were the problem must be, so I did a rephrase of my question.
Any help would be highly appreciated.
Rob
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.