【Django-CI系统】管理后台的列表增加方法字段-20220509

【Django-CI系统】管理后台的列表增加方法字段-20220509,第1张

增加方法字段
# 拓展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导出。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/885082.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-14
下一篇2022-05-14

发表评论

登录后才能评论

评论列表(0条)

    保存