如何将 Django 字段(如字段对象中的字段)保存到数据库?
我正在尝试实现一个可重用的表单,用户可以下载 HTML 格式的源代码,该源代码是由网站为他们生成的。他们还可以使用界面创建表单,在界面中选择所需的字段并对它们进行排名,以便最高的字段首先出现在可下载的表单中。
然后,他们可以在其网站中使用该表单来收集客户数据,当提交表单时,操作参数会指向我们的网站,以便我们可以将信息存储在我们的服务器上。
现在,我的问题是,如何在数据库中保存 Django Field 对象?这样我就可以存储用户创建的表单,尤其是他们选择的字段。
我需要存储字段,以便我可以创建通用的 Django ModelForm,并且用户可以将该 ModelForm 的字段保存在可下载的表单中。因此,当他们将信息提交给我们时,我可以将信息直接提供给 ModelForm(因为字段是可识别的)并进行一些进一步的验证。
另外,我还必须为每个字段添加一些基本的 javascript 验证(如validation.js)(当用户下载表单时必须存在),而且我知道如果我可以自己保存字段会更容易。
I'm trying to implement a reusable form that users can download the source code in HTML which was site generated for them by the site. They can also create their forms using an interface where they get to choose the fields they want and rank them so the highest would appear first in the downloadable form.
They can then use the form in their sites to gather customer data and when the form gets submitted, the action parameter points back to our site so we can store the information on our servers.
Now, my question is, how can I save a Django Field object in my database? This is so I can store the forms that the users created, especially the Fields that they chose.
I need to store the Fields so that I can create a generic Django ModelForm and the users can save the Fields of that ModelForm in their downloadable forms. So when they submit back the information to us I can feed the information straight to the ModelForm (since the Fields would be recognizable) and do some further validation.
Also I have to add some basic javascript validations (like validation.js) for each field (must be present when the user downloads the form), and I know it will be easier if I can save the Fields themselves.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以腌制 Field 对象:
要取消腌制:
http://docs.python.org/library/pickle .html
You could pickle the Field object:
To unpickle:
http://docs.python.org/library/pickle.html