2

I have a rather long form that users can't always complete in one sitting. I'd like users to be able to hit a button and save the form for completion later. My first thought was to simply save the form anyway and just flag it as incomplete somehow. However, I can't seem to get around the fact that incomplete forms are invalid and can't be forced to save. For example, if a required field near the end of the form is blank the form can't be saved to the database even if I skip the form.is_valid() step.

Is there another way to save the form's data temporarily? Also, I'm aware this question has been asked before but I'm afraid this answer wasn't very helpful: Django Save Incomplete Progress on Form

Update Thank you all for the responses so far. Some of the answers below made me realize I omitted a detail from my original question. I need to be able to let the user choose whether or not to finish a form when they return. The users enter information into this form several times a day. They may come back to the form not ready to finish form item A but instead needing to fill out form item B from the beginning. So, just auto-populating the form with their last incomplete form won't quite do the trick. I'm sorry this didn't occur to me when I posted the original question.

6
  • What about the dictionary-based approach wasn't very helpful? Is there something about that approach that you'd like to understand better? Commented Mar 13, 2013 at 18:55
  • Answer to previous question was pretty clear. Follow link to book in chosen answer for more details. Commented Mar 13, 2013 at 19:02
  • You mean the poster's original idea to just create a dictionary of the field and it's value? The poster didn't sound too keen on the idea and nobody else chimed in to say, "No, that will work." I get the part about making the dictionary but I guess I'm not understanding where to store that dictionary. Do you write it to a database somehow or is a shelve file something you can just write to a directory and read back later? If I knew a good way to save a dictionary long term I could certainly give it a shot. Commented Mar 13, 2013 at 19:03
  • There are a few approaches you could take for persistence: database, cookie, redis, etc. Commented Mar 13, 2013 at 19:14
  • You could serialise the form (json maybe?) and save it to the session, populating the form again when the user returns. Commented Mar 13, 2013 at 20:33

2 Answers 2

0

If you use django-merlin you can split up that long ass form into lots of smaller forms, and each previous form will be saved in the user's session just waiting for them to come back to it. If they navigate away and come back to it through the wizard's base url, they will be resumed at the same place they left off.

Sign up to request clarification or add additional context in comments.

Comments

0

I was asked to implement this type of functionality for the Django form wizard. The solution I came up with (without going too deep into the details) was to save the cleaned data at every step in a json format (json.dumps(self.get_all_cleaned_data()) to a table in my database.

Later, if someone wanted to resume the form, they could retrieve the record from the database and the information could be repopulated into the form using the (initial.update) method (def get_form_initial(self, step):). Hope this helps give you an idea.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.