将派生字段添加到 Django 管理更改表单

发布于 2024-10-04 14:31:56 字数 291 浏览 0 评论 0原文

我想将派生字段添加到默认的 ModelAdmin.fieldsets 中,就像通过指定方法并将其添加到 ModelAdmin.list_display 属性中一样,但似乎没有一种简单的方法可以做到这一点(如果有任何方法都可以做到这一点)。

默认的 Django 管理列表视图似乎比更改表单视图有更多的选项。

假设我有两个位置字段:纬度和经度,我不想在更改表单上显示它们,而是想显示 Google 地图静态地图图像 - 我已经有一个方法可以返回图像的 src url -我只需要一种方法将该图像添加到模型更改表单中,而不是显示这两个字段。

I'd like to add a derived field to a default ModelAdmin.fieldsets like I would by specifying a method and adding it to the ModelAdmin.list_display property, but there doesn't seem to be an easy way to do that (if there is ANY way to do that).

The default Django Admin list view seems to have a lot more options than the change form view does.

Let's say I have two fields for a location: latitude and longitude, and instead of displaying them on a change form I want to display a Google Maps Static Map image instead - I already have a method that will return the src url for the image - I just need a way to add that image to the model change form instead of showing those two fields.

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

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

发布评论

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

评论(2

无声无音无过去 2024-10-11 14:31:56

如果您编写一个方法并将其添加到 ModelAdmin.readonly_fields,它将出现在更改视图上。

If you write a method and add it to ModelAdmin.readonly_fields, it will appear on the change view.

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