需要用到bootstrap
models.py
class TransactionRecord():
""" 交易记录 """
charge_type_class_mapping = {
1: "success",
2: "danger",
3: "default",
4: "info",
5: "primary",
}
charge_type_choices = ((1, "充值"), (2, "扣款"), (3, "创建订单"), (4, "删除订单"), (5, "撤单"),)
charge_type = models.SmallIntegerField(verbose_name="类型", choices=charge_type_choices)
...
color.py
from django.template import Library
from web import models
register = Library()
@register.filter()
def colors(num):
return models.TransactionRecord.charge_type_class_mapping[num]
customer_charge.html
<table class="table table-bordered">
<thead>
<tr>
<th>ID</th>
<th>类型</th>
<th>金额</th>
<th>订单号</th>
<th>时间</th>
<th>其它</th>
</tr>
</thead>
<tbody>
{% for row in pager.queryset %}
<tr row-id="{{ row.id }}">
<td>{{ row.id }}</td>
<td>
<span class="btn btn-xs btn-{{ row.charge_type|colors }}">{{ row.get_charge_type_display }}</span>
</td>
<td>{{ row.amount }}</td>
<td>
{% if row.order_id %}
{{ row.order_oid }}
{% else %}
-
{% endif %}
</td>
<td>{{ row.create_datetime|date:"Y-m-d H:i:s" }}</td>
<td>
{% if row.memo %}
{{ row.memo }}
{% else %}
-
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>