9

I have a large Django model (73 fields) that will will be connected to a ModelForm. I'd like to use a combination of the functionality found the Form Wizard and Form Preview contrib apps.

I.e., the form fields would be split over multiple pages, and the user would have a chance to review/preview the data before the model instance is created.

Are there any best-practices for this type of thing, or example code?

Brian Tol
  • 4,149
  • 6
  • 24
  • 27
  • 1
    It's not worth an answer but anyway: It can be problematic to use FormWizard for anything beyond most trivial things (at least, it was for me). Here's one thing - you can't control what is passed to the form's `__init__` in an obvious way (besides the initial values). So how are you going to supply an "instance" keyword argument to the form's `__init__`? Of course there *are* ways - I, for example, solved it by declaring an inner class, that inherits from the neccessary ModelForm and overriding `__init__`. Then you must assign that class to an element of .form_list. Not very obvious ... – shylent Nov 11 '09 at 16:33
  • 1
    ... and you have to deal with such things a lot if you are going to use FormWizard. I'm not saying, that FormWizard is bad, but it is, certainly, not very easy to use. And 73 fields? I know, this might sound dumb, but, perhaps, there is a way to simplify the task by breaking it up in a number of smaller tasks? Like restructuring your models and dealing separately with each of them or something? – shylent Nov 11 '09 at 16:35
  • Thanks for the feedback, shylent. believe it or not the 73 fields _is_ simplified. It's just a lot of data we need to collect. :-) – Brian Tol Nov 11 '09 at 16:49

2 Answers2

1

I do a similar thing at my first Django project. Using session-based FormWizard, I customized it so user can stop subbmiting data at any form.

At that point you can use FormPreview probably to show information or just dynamically generate form and show it to user. Data stays in the session.

iElectric
  • 5,633
  • 1
  • 29
  • 31
0

You can pass the entire dictionary to the context and then access it in your template:

# views.py
def get_context_data(self, **kwargs):
    context = super(MyWizard, self).get_context_data(**kwargs)
    context['all_data'] = self.get_all_cleaned_data()
    return context

# template.html
{{ all_data }}
Özer
  • 2,059
  • 18
  • 22