python - django-simple-history,在管理中显示更改的字段

标签 python django django-simple-history

当我从 admin.ModelAdmin 继承时,在管理页面的历史记录中,我可以看到哪些字段已更改。但是,现在我需要使用 django-simple-history 来跟踪我所有的模型更改。现在,对于管理员,我继承了 simple_history.SimpleHistoryAdmin。虽然我可以看到所有模型更改并还原它们,但我看不到更改了哪些字段。是否可以将这种方便的功能添加到 SimpleHistoryAdmin 中?

最佳答案

您需要的是history_list_display管理员中的字段。 history_list_display 中包含的字段列表将与相应条目一起显示在历史记录页面中。

像这样的东西:

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',)

这将显示 field1 , field2连同 comment , userreason

关于python - django-simple-history,在管理中显示更改的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46892851/

相关文章:

django - 如何过滤同一列的多个值

python - heroku 不支持 django 应用程序并引发错误

python - 如何获取修改对象的用户? Django 简单历史

python - 如何在 Ansible 中转换字符串列表中的对象列表?

python - 解析文本文件并对某些值进行分组

python - 两个大型数据集的最快迭代合并

python - Pygame Sprite 碰撞检测不起作用

javascript - Google+ 登录 - 未捕获的安全错误

django - 如何使用 django-simple-history 恢复更改,特别是删除