django admin - 添加额外的复选框以与操作下拉列表一起使用

发布于 2024-09-29 03:03:33 字数 457 浏览 5 评论 0原文

我想使用 django 管理应用程序连接两个记录(作为父记录和子记录)。

使用此处的管理操作指南: http://docs.djangoproject.com /en/dev/ref/contrib/admin/actions/ 我编写了一个函数,它几乎通过利用操作下拉列表(在列表视图上)来完成此操作。我所拥有的是用户勾选两条记录,然后从下拉列表中选择建立连接,这会触发我的自定义函数以在两条记录之间建立连接(将一条记录的外键设置为另一条记录)。

然而,由于它是父子关系,因此顺序很重要,所以我想要的是 2 行复选框,一排说父母,另一排说孩子。然后,用户在每一行中勾选一个,然后运行该函数。

所以我想知道使用 django admin 执行此操作的最佳方法是什么?

I want to use the django admin app to connect two records (as a parent and child).

Using the admin actions guide here: http://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/ I have wrote a function which almost does this by utilises the actions dropdown (on the list view). What I have is the user ticks two records and then selects make connection from the dropdown which triggers my custom function to make the connection between the two (setting the foreignkey of one record to be the other).

However since it is a parent and child relationship the order is important so what I'd like is 2 rows of tickboxes one saying parent and the other saying child. The user would then tick one in each row then then running the function.

So what I'd like to know is what is the best way to do this using the django admin?

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

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

发布评论

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

评论(1

盗琴音 2024-10-06 03:03:34

有一个 ForeignKey 字段不是更好吗链接到同一模型(环回关系),您可以在其中选择父条目?

class MyRecord(models.Model):
   parent = models.ForeignKey(MyRecord)
   ....

然后是 django-mptt

Wouldn't it be better to have a ForeignKey field that links to the same model (loopback relationship) where you can select your parent entry?

class MyRecord(models.Model):
   parent = models.ForeignKey(MyRecord)
   ....

Then there's django-mptt

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