Django 用户认证 用户 邮箱登录 邮箱注册 ORM or,and,not form.py FORM ModelForm Paginator 分页 HTMl JQuery 定位元素 ajax django切片 restfulapi 跨域 Ubantu Python Mysql Scrapy 爬虫 导出 Python读写 Pycharm 破解 session re sqlit3 生成式 其他 Prism 富文本 CSS Nginx 部署 请求头 抓包 协议 selenium Ubuntu 宝塔 AI Comfy-ui ollama dify open-webui Git docker
django 通过LogEntry实现后台显示日志记录字段
张建行 2018年6月22日 14:37 19 文章标签: Django Ubantu Python 导出 部署

在admin.py中导入 LogEntry

from django.contrib.admin.models import LogEntry1

然后在admin中定义类添加新字段

class LogEntryAdmin(ImportExportModelAdmin):
    def logging(self, obj):  # 添加详细日志记录字段
        ip = format_html("<a>{}<a/>", (obj))
        return ip

    logging.short_description = "日志记录"  # 设置该字段字段显示的名字
    readonly_fields = ["logging"]  # 设置在点击到详情页中显示该字段
    # 记得在list_display中添加新的字段 logging
    list_display = ['user', 'action_time', 'logging', 'action_flag', 'content_type', 'object_id']
    show_detail_fields = ['user', 'action_time', 'logging', 'action_flag', 'content_type', 'object_id']


admin.site.register(LogEntry, LogEntryAdmin)  # 注册日志记录字段```