Skip to content

Instantly share code, notes, and snippets.

@jbzdak
Created February 24, 2019 13:12
Show Gist options
  • Save jbzdak/89d375b304f5a59f8141c31509bb4781 to your computer and use it in GitHub Desktop.
Save jbzdak/89d375b304f5a59f8141c31509bb4781 to your computer and use it in GitHub Desktop.
Django AdminLog inline
# See this article for discussion: http://blog.askesis.pl/post/2019/02/django-admin-inline.html
from django.contrib.admin.checks import BaseModelAdminChecks
from django.contrib.admin.models import LogEntry
from django.contrib.contenttypes.admin import GenericStackedInline
class ModelAdminLog(GenericStackedInline):
model = LogEntry
# All fields are read-only, obviously
readonly_fields = fields = ["action_time", "user", "change_message"]
# No extra fields so noone can add new logs
extra = 0
# No one can delete logs
can_delete = False
# This is a hackity hack! See below
checks_class = BaseModelAdminChecks
def change_message(self, obj):
return obj.get_change_message()
@admin.register(models.MyModel)
class MyModelAdminAdmin(admin.ModelAdmin):
# ...
inlines = [ModelAdminLog]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment