-1

Is here any way to store formset to a session ?


My Scenario is like this . I have a form to fill user data and upload user certificates, and in the next page(form by clicking next) there is a form to enter Professional details .

Is it possible to limit Maximum number of forms generated using a formset?

Ani Varghese
  • 403
  • 2
  • 6
  • 17

2 Answers2

1

If I understand your question correctly - how to save a state of the from in a session, then starting with Django 1.4, it actually comes with a way on how to do that out of the box.

https://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/

It allows you to split a form into multiple section, which then user can fill separately. Once user fills any one section, he/she go to the next page, at which point the state of the form will be saved in a session. Once all the pages are filled, then everything can be saved to a database.

In addition, while going from one page to the other, you add logic of what should be on the next page.

Image that you have a wizard where on the first page it asks what type of content user wants to upload. Then upon going to the second page, then depending on the answer from the first page, appropriate upload fields can be present - field for video, music, or graphics.

miki725
  • 27,207
  • 17
  • 105
  • 121
  • Thanks . but formwizard is not the right option for me as i have a link to view previous form ... Actually formwizard ruined a whole day of mine :( – Ani Varghese Sep 19 '12 at 12:45
  • Sorry to hear that. Then please clarify the question. Your question is abstract and it not clear. If you are having specific issue, ask that. If you get exceptions, ask that. More on how to ask good questions can be found at StackOverflow FAQ at http://stackoverflow.com/faq – miki725 Sep 19 '12 at 12:49
  • The issue is like this i have a registration module with three forms and the user able to go to next and previous forms , so i think it is better to go by saving form data to sessions. And there are two formsets in each form (adding certificates, urls, images, emails) etc. – Ani Varghese Sep 19 '12 at 13:01
0

I would have answered FormWizard but if you don't want to use it, you can simply create two forms. when the user submit the first one, you pickle it into a session and then you generate the second form. When he clicks on back link, you unPickle saved data and you prefill the form.

def submitFirstForm(request):
  data = request.POST['data']
  import cPickle        
  request.session['data'] = cPickle.dumps(data)
  ...

 def backBtn(request):
   import cPickle
   data = cPickle.loads(request.session['page'])
   form = DataForm(data)
   ...
Kamagatos
  • 854
  • 9
  • 12