django后台对某些字段设置颜色
在model.py的class函数中添加如下代码
#对签收状态设置颜色 def color_state(self): if self.assign_notice_state == '1': assign_state_name = '待签收' color_code = 'red' else: color_code = 'green' assign_state_name = '已签收' return format_html( '<span style="color:{};">{}</span>', color_code, assign_state_name, ) color_state.short_description = '签收状态'
adminx.py文件
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。list_display = ['assign_notice_title',....,'color_state','qianshou']
效果

更多精彩