django 中的计算字段可以通过@property来标识,然后可以在list_display属性在列表中显示出来。
在admin中:
但是这里有一个问题,list中默认显示的是Amount,怎么能修改amount这个字段的显示名字呢?
我们需要先去掉amount方法的@property装饰,为什么?因为如果被property装饰了,会报以下错误:AttributeError: 'property' object has no attribute 'short_description'
按照如下代码修改:
这样就可以显示出verbose name来了。
效果如下