在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文件

list_display = ['assign_notice_title',....,'color_state','qianshou']

效果

 

posted on 2019-04-11 16:08  曹婷婷  阅读(1989)  评论(0编辑  收藏  举报