Django Wizard Form and other view in one page
Django Wizard Form and other view in one page
I'm trying to show a wizard form and a table (that is generated by this form and can be seen in every step) in one page. Is it possible?
I have tried:
urls.py
urlpatterns = [url('', GroupsWizard.as_view(form_list), name = 'index'),]
views.py
def index(request):
groups_render = Groups.objects.all()
return render(request, 'index.html', 'groups_render' : groups_render)
class GroupsWizard(SessionWizardView):
def get_template_names(self):
return 'index.html'
def done(self, form_list, **kwargs):
data = k: v for form in form_list for k, v in form.cleaned_data.items()
instance = Groups.objects.create(**data)
return render(self.request, 'done.html',
'form_data': [form.cleaned_data for form in form_list],
)
index.html
<div>
wizard.form.management_form
% for form in wizard.form.forms %
form
% endfor %
</div>
<div>
groups_render
</div>
Thanks
1 Answer
1
I found it,
I used get_context_data function in views.py:
class GroupsWizard(SessionWizardView):
def get_template_names(self):
return 'index.html'
def get_context_data(self, form, **kwargs):
context = super(GroupsWizard, self).get_context_data(form = form, **kwargs)
context_data = Groups.objects.all()
context.update('context_data': context_data)
return context
def done(self, form_list, **kwargs):
data = k: v for form in form_list for k, v in form.cleaned_data.items()
instance = Groups.objects.create(**data)
return render(self.request, 'done.html',
'form_data': [form.cleaned_data for form in form_list],
)
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.