Django Form 2 阶段

发布于 2024-11-26 04:49:17 字数 385 浏览 0 评论 0原文

我正在尝试制作一个需要 2 个表单的 Django 订单系统。第一种形式让用户选择一些数量和一些基本联系信息。然后,使用他们订购的每件商品的数量生成第二个表格,允许他们为每件商品选择一些选项。该系统专门用于活动门票。以下是两个阶段:

1) 获取订单信息,例如下订单人的姓名、地址、电话。还要了解有多少人参加每个可能的活动。

2) 根据每个活动的人数,获取他们的姓名和电子邮件地址。

我已经创建了这两种表格。我只是被风景绊倒了。当他们提交表格 1 时,我需要获取该信息并保存其中一些,然后将其发送到表格 2。在表格 2 中,他们将填写其余信息并完成处理。

在这种情况下您将如何设置视图?我本质上需要从另一个视图中调用并在之间传递数据。我尝试使用 kwargs,但在处理第二种形式时遇到问题。

I'm trying to make a Django order system that requires 2 forms. The first form, lets users choose some some quantities and basic contact info some. Then, using the quantities of each item they ordered I generate a 2nd form which allows them to choose some options for each item. This system is specifically for event tickets. Here are the 2 stages:

1) Get the order info such as name, address, phone of the person placing the order. Also find out how many people are coming to each of the possible events.

2) Based on the number of people per event, get their name and e-mail address.

I already have both forms created. I am just getting tripped up in the views. When they submit form 1, I need to take that info and save some of it and then send them to form 2. At form 2, they will fill out the rest of the info and finish processing.

How would you set up the views in such as case? I essentially nee-d to call on view form another and pass data between. I tried using kwargs, but I have trouble processing the second form.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

居里长安 2024-12-03 04:49:17

如果没有看到模型,就很难给出精确的解决方案,但一种方法是有两个单独的视图,每个表单一个。

处理完第一个表单后,您很可能会获得从第一个表单创建的某个对象的实例。听起来您只需将该对象的 id 传递到下一个视图,然后您就可以在其中获取该对象并执行您需要的任何关联。

另外,听起来您可能需要从表单的多个实例收集数据......

(2) 根据每个活动的人数,获取他们的姓名和电子邮件
地址。)

为此,您需要使用 formset

Without seeing your models, it's hard to give an exact solution, but one approach is to have two separate views, one for each form.

Once you've processed the first form, you're most likely going to have an instance of some object that you created from the first form. It sounds like you just need to pass the id of that object to your next view where you could then get that object and do whatever association you need.

Also, it sounds like you might need to be collecting data from several instances of a form...

(2) Based on the number of people per event, get their name and e-mail
address.)

You'll want to use a formset for that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文