django自定义模板显示不同状态的颜色

一般这个颜色列表是放在models.py里

charge_type_class_mapping = {
        1: "success",
        2: "danger",
        3: "default",
        4: "info",
        5: "primary",
    }

 color.py

from django.template import Library
    from web import models
    register = Library()
    @register.filter()
    def type_color(charge_type_num):
        return models.TransactionRecord.charge_type_class_mapping[charge_type_num]

 

posted @ 2023-03-31 13:31  super_ip  阅读(57)  评论(0编辑  收藏  举报