admin后台

在 get_queryset 方法中,展示类模型中的统计数据,这个统计数据,不是在数据库中生成的,实在模型类中定义的方法,这个方法的返回值,可以在列表页中直接展示。例如上文中说道的标签的个数

同时,也可以返回一个HTML标签,模板语法中获取这个字段时,得到的是一个HTML标签,直接渲染

1
2
3
4
5
6
7
8
9
10
from django.utils.safestring import mark_safe
# 使用mark_safe
@mark_safe
def get_user_dept(self,obj):
  """ 这个方法在模型中 """
  return "<p>this is a HTML tag</p>"
# 允许HTML标签
get_report_depts.allow_tags = True
# HTML展示时的字段名
get_report_depts.short_description = '所属部门'

 

 

https://www.cnblogs.com/gtea/p/12966435.html

https://blog.csdn.net/weixin_42134789/article/details/113287454

posted on 2022-11-06 15:12  ldx-wsj  阅读(18)  评论(0)    收藏  举报