Reputation: 58
Well, I have to send files posted by one form to other form, I have to read an XML file first, if the file is valid I'll redirect to the next form, which has to have the valid file received in the past form. I tried with sessions but I'm not sure if it's the right way to go, here my models.
class InitialForm(models.Model): ... name = models.CharField(max_length=50) xml = models.FieldField(label='Please choose an XML file') ... class SecondForm(models.Model): ... name = models.CharField(max_length=50) pdf = models.FieldField(label='Please choose a PDF file') ...
The reason I got two forms is because I've got to read the XML first and validate it, and then in the next form 'SecondForm' show the data I just parse from the XML in order to verify and give feedback to the user. Then both files must be inserted in a database, only if the first one is valid.
Any help will be welcome. Thanks in advance.
Upvotes: 1
Views: 108
Reputation: 10252
I think what you need is a form wizard that Django offers for situations when you need to build a form that is split into multiple requests.
From their docs this is how it works:
The user visits the first page of the wizard, fills in the form and submits it.
The server validates the data. If it’s invalid, the form is displayed again, with error messages. If it’s valid, the server saves the current state of the wizard in the backend and redirects to the next step.
Step 1 and 2 repeat, for every subsequent form in the wizard.
Once the user has submitted all the forms and all the data has been validated, the wizard processes the data – saving it to the database, sending an email, or whatever the application needs to do.
Upvotes: 1