Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging activity on Django's admin - 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.

like image 579
RadiantHex Avatar asked Jul 01 '10 12:07

RadiantHex


People also ask

How do I log activity in Django?

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.

What is Django admin log?

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.

How do I restrict access to admin pages in Django?

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 .


2 Answers

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!

like image 170
Katharine Avatar answered Oct 04 '22 08:10

Katharine


Log is in django_admin_log table in database used by django.

like image 30
zaynyatyi Avatar answered Oct 04 '22 06:10

zaynyatyi