- July 9, 2009
- log request logging django-admin django_admin_log extended change_view
- 3 (after 3 ratings)
The django_admin_log only logs changes, not simple requests.
Sometimes it can be useful to log when a user of your admin interface is checking out important data, for instance if you are making a system with personal sensitive data, that needs to comply with government / company policies.
This will log such hits to the django_admin_log by overriding the change_view method in ModelAdmin.
So you must override this method in all classes you want to have logged.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
xlogging.py: from django.contrib.contenttypes.models import ContentType from django.utils.encoding import force_unicode VIEW = 4 def log_view(request, object): """ Log that an object is being viewed by the user. """ from django.contrib.admin.models import LogEntry LogEntry.objects.log_action( user_id = request.user.pk, content_type_id = ContentType.objects.get_for_model(object).pk, object_id = object.pk, object_repr = force_unicode(object), action_flag = VIEW, change_message = "Accessed object %s in %s." % (force_unicode(object), ContentType.objects.get_for_model(object)) ) admin.py from some.application.module.xlogging import log_view class SomeAdmin(admin.ModelAdmin): def change_view(self, request, object_id, extra_context=None): object = self.queryset(request).get(pk=unquote(object_id)) log_view(request, object) return super(SomeAdmin, self).change_view(request, object_id, extra_context)
More like this
- Password Obfuscation Log Filter by nikmolnar 2 years, 11 months ago
- group_required decorator by msanders 6 years, 9 months ago
- Load Template from App by mikob 2 years, 5 months ago
- FieldLevelPermissionsAdmin by buriy 8 years, 8 months ago
- Load template from specific app by king 7 years, 2 months ago