pythondjangodjango-simple-history

django-simple-history, displaying changed fields in admin


When I inherit from admin.ModelAdmin, in history on admin page I can see what fields has been changed. However, now I need to use django-simple-history to track all my model changes. Now, for admin, I inherit for simple_history.SimpleHistoryAdmin. Whilst I can see all of the model changes and revert them, I cannot see, which fields were changed. Is it possible to add that handy functionality to SimpleHistoryAdmin?


Solution

  • What you need is history_list_display field in your Admin. The list of fields included in the history_list_display will be displayed in the history page with their corresponding entries.

    Something like this:

    class SomeAdmin(admin.ModelAdmin):
    
        def some_user_defined(self, obj):
            return "something"
    
        date_hierarchy = 'created_at'
        search_fields = ['field1', 'field2']
        list_display = ('field1', 'field2',)
        list_filter = ('field1',)
        history_list_display = ('field1', 'field2', 'some_user_defined',)
    

    This will display field1, field2 along with comment, user and reason