使用选定的操作项扩展 django 模型

发布于 2024-12-13 19:13:36 字数 596 浏览 5 评论 0原文

在我的应用程序中,我有一组可能是(最多)一个团队的成员的玩家。我正在玩家管理视图中实现自定义操作,在其中选择玩家并与这些玩家创建一个新团队,遵循以下示例:www.jpichon.net/blog/2010/08/django-admin-actions-and-intermediate -pages/

然而,我感觉应该有一种比使用完全定制的模板更少 django 侵入的方法来实现这一点。我的想法是:Team 类的正常 ModelForm 是否可以扩展为接受来自创建团队操作的参数?不过,我很难找到有关该主题的一些文档。

这是我到目前为止所拥有的屏幕截图(遵循上述指南):

在此处输入图像描述

我想要导致类似的结果:

在此处输入图像描述

使用自定义模板时,第一部分工作正常,但我不知道如何(很好地)延伸Teams 的现有管理页面用于接受操作中的玩家参数。我想第三步(单击“创建团队”按钮后)可以通过覆盖团队模型表单的 save() 方法来完成?

感谢您的帮助!

In my application, I have a set of players who may be a member of (at most) one team. I am implementing a custom action in the player admin view where I select players and create a new team with those players, following the example at: www.jpichon.net/blog/2010/08/django-admin-actions-and-intermediate-pages/

However, I'm sensing that there should be a less django-intrusive way of implementing this than using a fully customized template. What I'm thinking is: can the normal ModelForm for the Team class be extended to accept arguments when coming from the create team action? I struggle to find some documentation on the subject though.

This is a screenshot of what I have so far (following the above guide):

enter image description here

Which I would like to result in something like:

enter image description here

The first part works fine when using the custom template, but I cant figure out how to (nicely) extend the existing admin page for Teams to accept the player arguments from the actions. I suppose the third step (after clicking the 'Create Team' button) can be accomplished by overriding the save() method of the Team Modelform?

Thankful for any assistance!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文