FormWizard and FileFields (Django 1.4)

My FormWizard (Django 1.4) allows the user to step back and forth until the wizard completes. The wizard saves all the values ​​that the user has filled out and displays them if the user returns to the completed step.

This works fine, i.e. for CharField, but does not work for FileFields. If the user sends the file at the stage containing the FileField, and later returns to this step, he must download the file again.

Is there a way that the user does not need to reload the file?

Please note that form data is not yet stored in the database.

+5
source share
1 answer

, Django SessionWizardView ( NamedUrlSessionWizardView) get_form.

:

  • , .
  • .
  • None, , .

:

from django.contrib.formtools.wizard.views import NamedUrlSessionWizardView

class MyWizardView(NamedUrlSessionWizardView):

    def get_form(self, step=None, data=None, files=None):
        if step:
            step_files = self.storage.get_step_files(step)
        else:
            step_files = self.storage.current_step_files

        if step_files and files:
            for key, value in step_files.items():
                if files.has_key(key) and files[key] is not None:
                    step_files[key] = files[key]
        elif files:
            step_files = files

        return super(MyWizardView, self).get_form(step, data, step_files)
+2

All Articles