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?

kostr22
  • 576
  • 7
  • 27
  • 2
    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. – Alex Zamai Jan 31 '18 at 14:42

1 Answers1

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.

Conans
  • 461
  • 1
  • 4
  • 14