类似于 Wufoo 的 Web 界面(可拖动元素、记住状态)
我的问题非常具体。我想要一个可以创建表单的应用程序,就像在 Wufoo 上一样,具有易于使用的界面。这意味着可拖动元素。
我的问题是,一旦使用更改了表单元素的顺序位置,我无法弄清楚如何将状态保存在数据库中。我可以做前端,并且有可用的库,但是如何在后端保存表单的特定实例,以便下次使用登录时,顺序是相同的。
我很想在这个应用程序中使用 Django。所以,我能想到的基本类是:
class Form(models.Model):
"""...objects..."""
class TextField(models.Model):
"""...objects..."""
#FK to Form()
class TitleArea(models.Model):
"""...objects..."""
#FK to Form()
我还可以在 HTML 表单中的元素上拥有特定的 ID:
<input id="Field2" name="Field2" type="text"/>
他们 (Wufoo) 是如何做到这一点的?我的模型不正确吗?我知道这很天真。谢谢。
The question I have is very specific. I wanted to have an app where I can create forms, as on Wufoo, with easy to use interface. Which means, draggable elements.
My problem is that I cannot figure out how will the state be saved in the database once the use changes the ordinal position of the form elements. I can do the front-end side, and there are libraries available for that but how do I save a particular instance of the form in the backend so that the next time use logs in, the order is same.
I would love to use Django for this app. So, the basic classes I can think of are:
class Form(models.Model):
"""...objects..."""
class TextField(models.Model):
"""...objects..."""
#FK to Form()
class TitleArea(models.Model):
"""...objects..."""
#FK to Form()
I can also have specific ID's on the elements in the HTML form:
<input id="Field2" name="Field2" type="text"/>
How do they (Wufoo) do this? Is my Model not correct? I know it is naive. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
ModelForm
来使用模型实例创建表单。只需在用户完成编辑后保存模型,然后当您再次为他们创建表单时,使用该模型作为ModelForm
(或表单集)的实例:You can use
ModelForm
to create forms using a model instance. Just save the model after a user is done editing, and then when you create the form for them again use the model as an instance to yourModelForm
(or formset):隐藏的胜利输入字段。
假设:
如果你明白我的意思。
hidden input fields for the win.
suppose:
If you catch my drift.
好吧,一个好的起点是考虑一个用例。如果我是用户,我需要什么来构建表单?文本字段,当然——但还有什么呢?表格有标题吗?一个网址?有有效期吗?
当您绘制出此类信息后,您就可以开始在 Django 中构建您的模型。
Well, a good place to start is to think about a use-case. If I'm a user, what am I going to need available to me, to build a form? Textfields, sure -- but what else? Is the form going to have a title? A URL? An expiration date?
When you have this kind of information plotted out, then you can start building out your models in Django.