在 Django 中为 540 个字段创建输入表单。最好的方法?
create input form for 540 fields in django. Best approach?
我是 django 的新手,想听听您对如何为
table 有 540 个字段。最好的方法是什么?最好将模型形式拆分为多个组件还是创建一个模板来收集部分输入(每页多个输入)并处理所有字段?如果您能给我一些信息 and/or 示例,那就太好了。
谢谢。
Django 有一个 Form wizard 可以存储跨多个页面累积的信息,验证每个步骤。
How it works
Here’s the basic workflow for how a user would use a wizard:
- The user visits the first page of the wizard, fills in the form and submits it.
- The server validates the data. If it’s invalid, the form is displayed again, with error messages. If it’s valid, the server saves the current state of the wizard in the backend and redirects to the next step.
- Step 1 and 2 repeat, for every subsequent form in the wizard.
- Once the user has submitted all the forms and all the data has been validated, the wizard processes the data – saving it to the database, sending an email, or whatever the application needs to do.
您可以考虑的一种方法是将您的模型拆分为语义切片,每个语义切片都是一个独立的模型,具有更易于理解的字段数量。
然后使用一对一关系(由 OneToOneField 实现)将这些 "slice-models" 映射回您的主要对象。
在您的向导中,您可以在开始时启动一个 t运行saction 并仅在所有 运行 顺利通过时才提交。
我是 django 的新手,想听听您对如何为 table 有 540 个字段。最好的方法是什么?最好将模型形式拆分为多个组件还是创建一个模板来收集部分输入(每页多个输入)并处理所有字段?如果您能给我一些信息 and/or 示例,那就太好了。 谢谢。
Django 有一个 Form wizard 可以存储跨多个页面累积的信息,验证每个步骤。
How it works
Here’s the basic workflow for how a user would use a wizard:
- The user visits the first page of the wizard, fills in the form and submits it.
- The server validates the data. If it’s invalid, the form is displayed again, with error messages. If it’s valid, the server saves the current state of the wizard in the backend and redirects to the next step.
- Step 1 and 2 repeat, for every subsequent form in the wizard.
- Once the user has submitted all the forms and all the data has been validated, the wizard processes the data – saving it to the database, sending an email, or whatever the application needs to do.
您可以考虑的一种方法是将您的模型拆分为语义切片,每个语义切片都是一个独立的模型,具有更易于理解的字段数量。
然后使用一对一关系(由 OneToOneField 实现)将这些 "slice-models" 映射回您的主要对象。
在您的向导中,您可以在开始时启动一个 t运行saction 并仅在所有 运行 顺利通过时才提交。