Login

Show Logs on Django Admin

Author:
ekinertac
Posted:
September 12, 2017
Language:
Python
Version:
Not specified
Tags:
admin log logging
Score:
0 (after 0 ratings)

Place the code any admin.py file in your registered apps

 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
from django.contrib import admin
from django.contrib.admin.models import LogEntry

class LogEntryAdmin(admin.ModelAdmin):
    search_fields = (
        'object_id',
        'object_repr',
        'action_time',
        'action_flag',
        'change_message',
    )
    readonly_fields = ('content_type',
        'user',
        'action_time',
        'object_id',
        'object_repr',
        'action_flag',
        'change_message'
    )

    def has_delete_permission(self, request, obj=None):
        return False

    def get_actions(self, request):
        actions = super(LogEntryAdmin, self).get_actions(request)
        del actions['delete_selected']
        return actions

admin.site.register(LogEntry, LogEntryAdmin)

More like this

Comments

Please login first before commenting.