Skip to content

Commit dc3a34e

Browse files
committed
Added getter for admin's history_list_display
1 parent 18f00bd commit dc3a34e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Unreleased
1313
it will be removed in version 3.8 (gh-1128)
1414
- Added ``SimpleHistoryAdmin.get_history_queryset()`` for overriding which ``QuerySet``
1515
is used to list the historical records (gh-1128)
16+
- Added ``SimpleHistoryAdmin.get_history_list_display()`` which returns
17+
``history_list_display`` by default, and made the latter into an actual field (gh-1128)
1618

1719
3.5.0 (2024-02-19)
1820
------------------

simple_history/admin.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any
1+
from typing import Any, Sequence
22

33
from django import http
44
from django.apps import apps as django_apps
@@ -23,6 +23,8 @@
2323

2424

2525
class SimpleHistoryAdmin(admin.ModelAdmin):
26+
history_list_display = []
27+
2628
object_history_template = "simple_history/object_history.html"
2729
object_history_list_template = "simple_history/object_history_list.html"
2830
object_history_form_template = "simple_history/object_history_form.html"
@@ -54,7 +56,7 @@ def history_view(self, request, object_id, extra_context=None):
5456
historical_records = self.get_history_queryset(
5557
request, history, pk_name, object_id
5658
)
57-
history_list_display = getattr(self, "history_list_display", [])
59+
history_list_display = self.get_history_list_display(request)
5860
# If no history was found, see whether this object even exists.
5961
try:
6062
obj = self.get_queryset(request).get(**{pk_name: object_id})
@@ -121,6 +123,14 @@ def get_history_queryset(
121123
qs = qs.select_related("history_user")
122124
return qs
123125

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+
124134
def history_view_title(self, request, obj):
125135
if self.revert_disabled(request, obj) and not SIMPLE_HISTORY_EDIT:
126136
return _("View history: %s") % force_str(obj)

0 commit comments

Comments
 (0)