python - 如何在 Django 管理站点中显示 django-simple-history 的历史表?
问题描述
我已经使用 django-simple-history https://django-simple-history.readthedocs.io/en/2.10.0/index.html实现了对 Django 中对象更改的历史跟踪
我已经提到了history
Model 中的一个字段,我可以使用它来查询对象的历史记录。
history = HistoricalRecords()
我们还在数据库中创建了一个名为 name 的表appname_historicalmodelname
。
我想appname_historicalmodelname
在 django admin 中显示此表,其中我们有按 . 排序的记录列表history_time
。
由于我没有该 History 表的 Model 类,因此我无法使用admin.site.register(HistoricalModelName)
. 如何在 Django 管理站点中显示此表?
- 姜戈:1.11
- 蟒蛇:2.7
解决方案
django-simple-history
附带SimpleHistoryAdmin
,将“历史”按钮固定在您的正常管理视图中,允许您查看特定模型实例的历史记录。但是,如果您希望能够为历史记录本身创建 django 管理视图,您可以执行以下操作(假设CustomModel
app 中的基本模型my_app
):
from django.apps import apps
from django.contrib import admin
HistoricalCustomModel = apps.get_model("my_app", "HistoricalCustomModel")
@admin.register(HistoricalCustomModel)
class HistoricalCustomModelAdmin(admin.ModelAdmin):
...
推荐阅读
- github - 如何根据分支设置工作流环境变量
- angular - 'any[]' 类型的参数不能分配给'string' 类型的参数
- angular - 如何在.reduce中返回两个值?
- listview - 使用 searchview xamarin.android 使用适配器过滤列表视图
- python - 如何附加到正在运行的 Popen 进程
- linux - 使用 select() 和在循环中检查之间的区别
- python-3.x - 使用 API 网关非代理 lambda 和二进制输出设置自定义标头
- google-sheets - 没有计算正确的数字或刷新
- javascript - 以编程方式打开 ol-contextmenu
- xml - Ansible XML 更新