在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']

效果

django后台对某些字段设置颜色

 

相关文章:

  • 2022-12-23
  • 2021-07-25
  • 2021-10-30
  • 2022-12-23
  • 2021-10-14
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2022-02-21
  • 2022-12-23
相关资源
相似解决方案