I am using django-simple-history
for saving history of the objects. And it works fine. But I want to create a view in django admin that displays history records for all instances in model in one page.
For example I have a model
class TestModel(models.Model):
title = models.CharField('title', max_length=100)
history = HistoricalRecords()
and admin
class TestModelAdmin(SimpleHistoryAdmin):
list_display = ['title']
admin.site.register(TestModel, TestModelAdmin)
And now I can see the history of each instance.
Not sure how I can solve this problem. May be there is a way to create custom views in admin site (without model), or maybe I should create another model?
What's the best way to display all history records (for all instances) in admin panel?
Use the through
model of the TestModel.history
as admin model:
class HistoricalTestModelAdmin(admin.ModelAdmin):
list_display = ['title', 'history_object']
admin.site.register(TestModel.history.model, HistoricalTestModelAdmin)
The .history_object
refers to the object for which we track the history. So in this case we can for example find the historical titles of your TestModel
objects.