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.
You can implement a user activity monitoring system by adding the GitHub Gist at the bottom to any admin.py file in your project. This will allow you to see any change, addition, and deletion that happens in any model and know who made it by using the already saved data of Django Admin's LogEntry model.
Log entries are automatically created by the Django framework whenever a user adds, changes or deletes objects through the admin interface. Django Admin Logs is a package that allows you to either view the admin log entries from within the admin interface, or to disable them entirely.
Django admin allows access to users marked as is_staff=True . To disable a user from being able to access the admin, you should set is_staff=False . This holds true even if the user is a superuser. is_superuser=True .
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!
Log is in django_admin_log table in database used by django.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With