Saving multiple forms efficiently using Django's Form Wizad and the issue of missing list indexes -
I am using the Django form wizard in my app. There are five forms in total, although only three or four can be presented, because on the basis of one particular condition or two special forms, two forms can be omitted.
The contents of the list back by SessionWizardView method are as follows:
[& lt; Test.myapp.models.AForm object> 0x0177EC10, & lt; Test.myapp 0x01333540> test.myapp.models.EForm object; 0x01796910 & gt ;, test.myapp.models.DForm object at & lt; 0x01796530 & gt ;, test.myapp.models.CForm object at & lt; .models.BForm 0x01796150 & gt ;, Object on & lt; ] I save the following forms:
one = form_list [0] .save (committed = false) a.save () B = form_list [1] .save (committed = false) b.parent_id = a b.save () c = form_list [2] .save (committed = false) c.parent_id = a c.save () d = form_list [ 3] .save (committed = false) d.parent_id = a d.save () d = form_list [4] .save (committed = false) d.parent_id = a d.save () As you can tell, if only four forms are deposited, then the index index 4 does not exist and I am "out of the index index limit" If you are intelligent if only three form indexes are submitted 3 and 4 are non-existent, my question is two times; How can I overcome the issue of non-existent indexed indexes and how can I make the code more efficient?
Thank you very much
Um, you can set your form_list for statement, iterate can be done using .
Comments
Post a Comment