Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 537
Anil Panda Avatar asked Oct 23 '17 15:10

Anil Panda


People also ask

How can I remove extra's from Django admin panel?

You can add another class called Meta in your model to specify plural display name. For example, if the model's name is Category , the admin displays Categorys , but by adding the Meta class, we can change it to Categories . Save this answer.

What is Fieldsets in Django admin?

fieldsets is a list of two-tuples, in which each two-tuple represents a <fieldset> on the admin form page. (A <fieldset> is a “section” of the form.)

What we can do in admin portal in Django?

The Django admin application can use your models to automatically build a site area that you can use to create, view, update, and delete records. This can save you a lot of time during development, making it very easy to test your models and get a feel for whether you have the right data.


1 Answers

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

like image 141
Pramod Solanky Avatar answered Sep 27 '22 16:09

Pramod Solanky