Created
February 24, 2019 13:12
-
-
Save jbzdak/89d375b304f5a59f8141c31509bb4781 to your computer and use it in GitHub Desktop.
Django AdminLog inline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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