在Django模板中使用动态量的输入形成形式

发布于 2025-02-03 20:34:16 字数 544 浏览 2 评论 0原文

问题的症结在于: 我有一个架构,后来将转换为 .csv 文件。但是,我需要用数据填充此模式。为此,我需要具有字段的列(名称,数据类型,订单等) 但是我不知道有多少 架构 因此,措辞听起来像这样:创建一个具有动态数量列的形式

当我写这个问题时,我有一个想法在数据库中创建一个“ 方案”表,并绑定了一个表 - “ column” 因此,当您单击“添加列”时,将出现一个新实例,该实例将已经绑定到此架构。 我是在思考正确的方向还是还有另一个主意? 下图将使您更准确地传达问题的本质。 先感谢您

The crux of the problem is this:
I have a Schema that will later be converted to a .csv file. However, I need to populate this schema with data. To do this, I need columns that will have fields (Name, data type, order, etc.)
But I don't know how many columns the Schema will have
Therefore, the wording sounds like this: Create a form with a dynamic number of columns.

While I was writing the question, I had an idea to create a "Scheme" table in the database and bind a table - "Column" to it
Thus, when you click "add column", a new instance will appear that will already be bound to this Schema.
Am I thinking in the right direction or do you have another idea?
The picture below will allow you to convey the essence of the problem more accurately.
enter image description here
Thank you in advance

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

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

发布评论

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

评论(1

您的好友蓝忘机已上羡 2025-02-10 20:34:17

如果我处于您的位置,我将使用htmx。因此,当按下“添加列”按钮时,将会出现新的行。

从我对您的帖子的理解来看,我也会以相反的方式进行操作,我会将列绑定到这样的方案

class Scheme(models.Model):
...
# rows of scheme


class Column(models.Model):
    scheme = models.ForeignKey(scheme, models.CASCADE) 
...
# rows of column

If I was in your position, I would utilize HTMX. With that, when the "add column" button would be pressed, a new row would appear.

I would also do it the other way around from what I understand of your post, I would bind the column to the scheme like this

class Scheme(models.Model):
...
# rows of scheme


class Column(models.Model):
    scheme = models.ForeignKey(scheme, models.CASCADE) 
...
# rows of column
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文