Django admin actions logging: how to display initial and result value of field changes?
Asked Answered
Y

1

7

I want to add logging of admin changes in my django project. I've done some of that through LogEntry model:

from django.contrib.admin.models import LogEntry

class LogEntryAdmin(admin.ModelAdmin):
    list_display = ('__str__', 'action_time', 'user', 'content_type', 'object_id', 'object_repr', 'action_flag', 'change_message')
    list_filter = ('content_type',)
    search_fields = ['user__username',]
    date_hierarchy = 'action_time'

admin.site.register(LogEntry, LogEntryAdmin)

This is great, if I change some field of an object in my database, I can see log entry for that action. But in this log entry I can see only that "field was changed", and I also want to see initial and result value of this field. How can I achieve this functionality?

Yulandayule answered 25/9, 2015 at 11:38 Comment(1)
For me this question is still relevant, the answer from @conans does not provide an example of how this could be implemented. If there is a package that helps with that or example snipped, I'd also appreciate it.Lactate
R
0

You can extend the LogEntry class and add custom fields and then use pres_save, post_save etc., to store the required entries to your custom model.

Raddled answered 25/9, 2015 at 12:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.