Hi, > Depending on step 1's selection, I want to set the queryset of one of > the fields (a ModelChoiceField) > > e.g. > class StepOneForm(forms.Form): > channelType = > forms.ModelChoiceField(queryset=ChannelType.objects.all()) > class StepTwoForm(forms.Form): > channel = forms.ModelChoiceField() > > class MyFormWizard(FormWizard): > def process_step(self, request, form, step): > if step==0: > self.get_form(1).channel.queryset = > form.cleaned_data['channelType'].channel_set.all()
The process_step method is called only after the form is already validated. So, as you found out, that's not going to work. Also, you are trying to set the queryset on form #1 when step is 0. That's not going to persist. > But it doesn't seems working... how can a dynamic choice can be > achieved depending on selection of previous step?! Try overriding the get_form method instead of process_step. Also, you will need to populate form #1's queryset when you are in step 1. So, the code would be something like this: def get_form(self, step, data=None): form = super(MyFormWizard, self).get_form(step, data=data) if step == 1: # Get step #0's form and set form #1's queryset based on it form0 = super(MyFormWizard, self).get_form(0, data=data) form.fields['channel'].queryset = form0.cleaned_data['channelType'].channel_set.all() return form -Rajesh D --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---