|
1 |
| -from typing import Any |
| 1 | +from typing import Any, Sequence |
2 | 2 |
|
3 | 3 | from django import http
|
4 | 4 | from django.apps import apps as django_apps
|
|
23 | 23 |
|
24 | 24 |
|
25 | 25 | class SimpleHistoryAdmin(admin.ModelAdmin):
|
| 26 | + history_list_display = [] |
| 27 | + |
26 | 28 | object_history_template = "simple_history/object_history.html"
|
27 | 29 | object_history_list_template = "simple_history/object_history_list.html"
|
28 | 30 | object_history_form_template = "simple_history/object_history_form.html"
|
@@ -54,7 +56,7 @@ def history_view(self, request, object_id, extra_context=None):
|
54 | 56 | historical_records = self.get_history_queryset(
|
55 | 57 | request, history, pk_name, object_id
|
56 | 58 | )
|
57 |
| - history_list_display = getattr(self, "history_list_display", []) |
| 59 | + history_list_display = self.get_history_list_display(request) |
58 | 60 | # If no history was found, see whether this object even exists.
|
59 | 61 | try:
|
60 | 62 | obj = self.get_queryset(request).get(**{pk_name: object_id})
|
@@ -121,6 +123,14 @@ def get_history_queryset(
|
121 | 123 | qs = qs.select_related("history_user")
|
122 | 124 | return qs
|
123 | 125 |
|
| 126 | + def get_history_list_display(self, request) -> Sequence[str]: |
| 127 | + """ |
| 128 | + Return a sequence containing the names of additional fields to be displayed on |
| 129 | + the object history page. These can either be fields or properties on the model |
| 130 | + or the history model, or methods on the admin class. |
| 131 | + """ |
| 132 | + return self.history_list_display |
| 133 | + |
124 | 134 | def history_view_title(self, request, obj):
|
125 | 135 | if self.revert_disabled(request, obj) and not SIMPLE_HISTORY_EDIT:
|
126 | 136 | return _("View history: %s") % force_str(obj)
|
|
0 commit comments