Django在表单上保存不完整的进度 [英] Django Save Incomplete Progress on Form

查看:125
本文介绍了Django在表单上保存不完整的进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个django webapp,多个用户登录并填写表单。

I have a django webapp with multiple users logging in and fill in a form.

有些用户可能会开始填写表单,并且缺少验证表单所需的一些必需的数据(例如,授权#)(并且在开始处理之前) 。我希望他们能够填写表单,并有一个选项来保存部分信息(所以有一天他们可以重新登录并完成它)或提交正在验证的完整信息。

Some users may start filling in a form and lack some required data (e.g., a grant #) needed to validate the form (and before we can start working on it). I want them to be able to fill out the form and have an option to save the partial info (so another day they can log back in and complete it) or submit the full info undergoing validation.

目前,我正在使用ModelForm来处理所有使用的表单,并且Model有限制来确保有效的数据(例如,grant#必须是唯一的)。但是,我希望他们能够保存这个中间数据,而不会进行任何验证。

Currently I'm using ModelForm for all the forms I use, and the Model has constraints to ensure valid data (e.g., the grant # has to be unique). However, I want them to be able to save this intermediary data without undergoing any validation.

我认为的解决方案看起来似乎没有意义,而不是django-ey:创建一个保存部分表单按钮,可将POST字典保存到 shelf 文件中,并创建一个SavedPartialForm 将用户连接到保存在架子中的部分表单的模型。这似乎是明智的吗?有没有更好的方式将POST dict直接保存到db?或者是一个附加模块,这样做可以部分保存一个表单(这在Webforms中似乎是一个相当普遍的活动)?

The solution I've thought of seems rather inelegant and un-django-ey: create a "Save Partial Form" button that saves the POST dictionary converts it to a shelf file and create a "SavedPartialForm" model connecting the user to partial forms saved in the shelf. Does this seem sensible? Is there a better way to save the POST dict directly into the db? Or is an add-on module that does this partial-save of a form (which seems to be a fairly common activity with webforms)?

我最关心的是我的方法是我最终能够在一些ajax / jquery方法中自动执行自动保存(例如每10分钟一次),而不需要实际按压一个按钮并发送POST请求(例如,因此当触发自动保存时,用户不会被重定向到页面外)。我不熟悉jquery,并且想知道是否可以这样做。

My biggest concern with my method is I want to eventually be able to do this form-autosave automatically (say every 10 minutes) in some ajax/jquery method without actually pressing a button and sending the POST request (e.g., so the user isn't redirected off the page when autosave is triggered). I'm not that familiar with jquery and am wondering if it would be possible to do this.

推荐答案

有一个很好的解决方案在由Marty Alchin的Pro Django 。简而言之,您创建另一个模型,其中包含表单的哈希值,表单域和保存的值。恢复时,您只需按照哈希的形式加载表单。

There is a good solution in Pro Django by Marty Alchin. In a nutshell, you create another model that contains a hash of the form, the form field, and the value saved. When resuming, you just load according the form according to it's hash.

这篇关于Django在表单上保存不完整的进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆