According to the form wizard docs, the initial data should be a static dict. But is it possible to provide initial data dynamically?
Here is my situation:
def get_context_data(self, form, **kwargs):
context = super(debugRegistrationWizard, self).get_context_data(form=form, **kwargs)
email = InvitationKey.objects.get_key_email(self.kwargs['invitation_key'])
context.update({'invitation_key': self.kwargs['invitation_key']})
return context
The email is what I want for initial data in step0, but I can only get this email in get_context_data method. How can I do that?
By the way: if the urlconf for formwizard.as_view accept argument like:
url(r'^registration/(?P<invitation_key>\w+)$', debugRegistrationWizard.as_view(FORMS)),
does it mean I have to pass a variable to my form's action attributes, because otherwise when I submit the form, I will get a not found url error.
You can override the method get_form_initial
def get_form_initial(self, step):
initial = self.initial_dict.get(step, {})
if step == 42:
email = InvitationKey.objects.get_key_email(self.kwargs['invitation_key'])
initial.update({'email': email})
return initial
Ref: https://django-formtools.readthedocs.io/en/latest/wizard.html#formtools.wizard.views.WizardView.get_form_initial
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With