可以通过Django的admin监控django_admin_log吗?
表django_admin_log
对于监控管理员中用户的操作非常有用。现在,我可以通过直接查询数据库来实现这一点。是否有内置功能可以让我通过 Django 管理员查看所有用户的 django_admin_log 表?
The table django_admin_log
is useful to monitor the actions of users in the admin. Right now, I can achieve that by querying the database directly. Is there a built-in functionality where I can view the table django_admin_log
through Django's admin for all users?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你不能只是:
在你的 admin.py 文件之一中吗?我刚刚测试了它,它是准系统,但它可以工作。
您可能想要更具体,并为 LogEntry 创建一个
ModelAdmin
类,以提供更好的列表视图以及一些过滤功能。但这应该有效。Can't you just:
In one of your admin.py files? I just tested it and it is barebones but it works.
You might want to be more specific and create a
ModelAdmin
class for LogEntry to provide for a better list view and maybe some filtering abilities. But that should work.这是我的版本。 可用字段的参考。
Here's my version. Reference for fields available.
这是一个更广泛的管理配置,用于查看依赖于 Django 2.1 仅查看权限的所有日志条目:
它基于 this Django 片段 和结果如下所示:
如果您想将其与早期的 Django 一起使用版本,请参阅此答案的此早期版本。
Here's a more extensive admin configuration for viewing all log entries that relies on Django 2.1 view-only permissions:
It is based on this Django snippet and the result looks like this:
If you want to use it with earlier Django versions, see this earlier revision of this answer.
根据我的经验,有几点:
一个原因显然是因为这些是日志,不应该是可变的,但另一个原因是性能。例如,如果您允许更改用户,那么如果您有数十万用户(如我的情况),则单独加载更改页面可能会出现问题。否则,您可以使用
raw_id_fields
。我还为操作创建了过滤器,因为原始模型没有
CHOICES
字段,并且仅使用action_flag
作为过滤器将显示 1,2,3 作为选项,这不是'非常用户友好:Few points from my experience:
One reason is obviously because those are logs and should not be mutable, but another is performance. If you allow changing users for example, loading of change page on it's own can be issue if you have hundreds of thousands of users as in my case. Otherwise you can use
raw_id_fields
.I also created filter for action as orignal model does not have
CHOICES
field and using justaction_flag
as filter will show 1,2,3 as choices, which isn't very user friendly: