The django-simple-history package is awesome as it shows you all the activity on a certain Django model object. It allows seeing how it was mutated over time and who changed it. However, there is one caveat: you cannot easily see what objects were deleted as there is simply no direct reference anymore.
The problem had already been raised with some solutions already been provided, but these mainly focus on providing a filter to make them visible. The Gist below adds a new history page on the model's change list page. The benefit here is that you can override the
BaseHistoryAdmin to add for example filters or search functionality, that you would not have normally.
For example, to combine Django Simple History with DjangoQL you can add advanced searching like this:
from django.contrib import admin from djangoql.admin import DjangoQLSearchMixin class SomeHistoryAdmin(DjangoQLSearchMixin, BaseHistoryAdmin): # Add your specific DjangoQL settings here ... class SomeModelAdmin(WMSimpleHistoryAdmin): history_admin = SomeHistoryAdmin # The rest of your model settings ... admin.site.register(SomeModel, SomeModelAdmin)
For adding additional filters to the history admin you could do something similar by specifying
SomeHistoryAdmin.list_filter, by default it's already filtered on
history_type so you can quickly identify which objects were added, changed or deleted.
This example shows how to use DjangoQL to query orders that were deleted. By adding
templates/admin/change_list.html a button will be created on all model change list pages just before the regular Add button, it will refer to the history page. Beware that this also adds a button on admin pages that are not based on
Go ahead and tweak the Gist to your own needs: