在 Django 的管理员上记录活动 - Django [英] Logging activity on Django's admin - Django

查看:35
本文介绍了在 Django 的管理员上记录活动 - Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I need to track/log activity on the Django admin.

I know there are messages stored by admin somewhere, but I don't know how to access them in order to use them as a simple log.


I'm trying to track the following:

  • User performing the action

  • Action committed

  • Datetime of action

Thanks guys.

解决方案

I had to do something similar and I used something like this:

from django.contrib.admin.models import LogEntry

logs = LogEntry.objects.all() #or you can filter, etc.
for l in logs:
    #perform action

You can see all of the attributes for LogEntry, but I think the ones you are looking for are l.user, l.action_time and l.obj_repr (the name of the obj) and l.action_flag ({ 1:'Add',2:'Change',3:'Delete'}). Hope that helps!

这篇关于在 Django 的管理员上记录活动 - Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆