开发者

How can display a FloatField in a Django admin column rounded to the nearest integer, without using a custom list_display?

开发者 https://www.devze.com 2022-12-27 17:20 出处:网络
It would be easy with a custom list_display, but that w开发者_如何学Pythonould cause me to lose the sorting ability according to that column.The docs say this:

It would be easy with a custom list_display, but that w开发者_如何学Pythonould cause me to lose the sorting ability according to that column.


The docs say this:

However, if an element of list_display represents a certain database field, you can indicate this fact by setting the admin_order_field attribute of the item.

So you should define your function to display the rounded value, but set admin_order_field to preserve the ordering capability.

0

精彩评论

暂无评论...
验证码 换一张
取 消