[Django]-Override django admin activity log

4👍

The queryset of admin main page logs is defined by the template tag django.contrib.admin.templatetags.log.get_admin_log.

So you can override the log template tags library by redefining it in yourapp/templatetags/log.py (yourapp must be before django.contrib.admin in your INSTALLED_APPS, so that your log template tags library takes the precedence over django.contrib.admin‘s).

from django.contrib.admin.templatetags.log import *  # noqa

def __AdminLogNode_render(self, context):
    if self.user is None:
        entries = LogEntry.objects.all()
    else:
        user_id = self.user
        if not user_id.isdigit():
            user_id = context[self.user].pk
        entries = LogEntry.objects.filter(user__pk=user_id)
    entries = entries.exclude(content_type=4, action_flag=1)
    context[self.varname] = entries.select_related('content_type', 'user')[:int(self.limit)]
    return ''
__AdminLogNode_render.__name__ = 'render'

AdminLogNode.render = __AdminLogNode_render

Leave a comment