将派生字段添加到 Django 管理更改表单
我想将派生字段添加到默认的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您编写一个方法并将其添加到 ModelAdmin.readonly_fields,它将出现在更改视图上。
If you write a method and add it to ModelAdmin.readonly_fields, it will appear on the change view.
自定义管理视图 http://docs.djangoproject.com /en/dev/ref/contrib/admin/#ref-contrib-admin
customize admin view http://docs.djangoproject.com/en/dev/ref/contrib/admin/#ref-contrib-admin