在model.py的class函數中添加以下代碼html
#對簽收狀態設置顏色 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']
效果spa