增加方法字段
# 拓展User模型
class UserProfileAdmin(admin.ModelAdmin):
list_display = ['user', 'department', 'employeename','employeeid', 'title',
'role', 'score_ci', 'score_total', 'score_used','score_left','caculate_score',]
actions = (export_model_as_csv_for_EmployeeUser, )
def caculate_score(self, obj):
if obj.score_ci and obj.score_total and obj.score_used:
return mark_safe(obj.score_ci+obj.score_total-obj.score_used)
return 0
caculate_score.short_description = '剩余积分'
效果:新增了第二栏“剩余积分”
弊端:
方法字段较难直接CSV导出。