Django admin:格式化列表中的字段,但保持可排序?
我在数据库中保留“尺寸”、“宽度”、“高度”等数字字段。现在,当在更改列表中显示它们时,我会将“KiB”或“像素”等单位附加到它们上。通过向 list_display 添加“size_formatted”等可调用对象可以轻松实现这一点。但是,这些不再可排序。
有办法绕过这个限制吗?
I keep numeric fields like "size", "width", "height" in my database. Now I would attach units like "KiB" or "pixels" to them when showing them in the change list. This could easily be achieved by adding callables such as "size_formatted" etc to list_display. However, these are no longer sortable.
Is there a way around this limitation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
阅读此处 - ModelAdmin.list_display< /a> (阅读很多内容才能明白要点;))
您需要将 admin_order_field 属性添加到您的函数中
Read here - ModelAdmin.list_display (read a lot to get to the point ;) )
you need to add admin_order_field attribute to your function