I have a list of three pages coming out of one model. I could save the model first, but when I want to edit the model, only the first form shows the initial value, the subsequent forms do not show the original data. but when I print initial_dict from the views, I can see all the initial views correctly. I followed this blog in the form wizard.
Here is my model.py:
class Item(models.Model): user=models.ForeignKey(User) price=models.DecimalField(max_digits=8,decimal_places=2) image=models.ImageField(upload_to="assets/", blank=True) description=models.TextField(blank=True) def __unicode__(self): return '%s-%s' %(self.user.username, self.price)
urls.py:
urlpatterns = patterns('', url(r'^create/$', MyWizard.as_view([FirstForm, SecondForm, ThirdForm]), name='wizards'), url(r'^edit/(?P<id>\d+)/$', 'formwizard.views.edit_wizard', name='edit_wizard'), )
forms.py:
class FirstForm(forms.Form): id = forms.IntegerField(widget=forms.HiddenInput, required=False) price = forms.DecimalField(max_digits=8, decimal_places=2)
views.py:
class MyWizard(SessionWizardView): template_name = "wizard_form.html" file_storage = FileSystemStorage(location=os.path.join(settings.MEDIA_ROOT))
template:
<html> <body> <h2>Contact Us</h2> <p>Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}</p> {% for field in form %} {{field.error}} {% endfor %} <form action={% url 'wizards' %} method="post" enctype="multipart/form-data">{% csrf_token %} <table> {{ wizard.management_form }} {% if wizard.form.forms %} {{ wizard.form.management_form }} {% for form in wizard.form.forms %} {{ form }} {% endfor %} {% else %} {{ wizard.form }} {% endif %} </table> {% if wizard.steps.prev %} <button name="wizard_goto_step" type="submit" value="{{ wizard.steps.first }}">"first step"</button> <button name="wizard_goto_step" type="submit" value="{{ wizard.steps.prev }}">"prev step"</button> {% endif %} <input type="submit" value="Submit" /> </form> </body> </html>
EDIT: one I noticed, this is the following: In edit mode, i.e. When I am at the following URL: http://127.0.0.1:8000/wizard/edit/1/ , it displays the data of the first form correctly, and when I click the "Submit" button, this does not lead me to step 2 of the editing mode, those. The URL changes to http://127.0.0.1:8000/wizard/create/ .
If by clicking submit on the editing URL (for example, /wizard/edit/1 ) the same URL is supported in the first step, the form will receive its initial data in the next step. but i can't figure out how to avoid changing the url to /wizard/create