python - How to provide initial data to django form wizard? -


according form wizard docs, initial data should static dict. possible provide initial data dynamicly.

here 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 want initial data in step0, can email in get_context_data method. how can that?

by way if urlconf formwizard.as_view accept argument like:

url(r'^registration/(?p<invitation_key>\w+)$', debugregistrationwizard.as_view(forms)), 

dose mean have pass variable form's action attributes, because otherwise when submit form , not found url error.

you can override 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://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/#django.contrib.formtools.wizard.views.wizardview.get_form_initial


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -