77from django .contrib .auth import get_permission_codename , get_user_model
88from django .core .exceptions import PermissionDenied
99from django .shortcuts import get_object_or_404 , render
10+ from django .template .defaultfilters import truncatechars
1011from django .urls import re_path , reverse
1112from django .utils .encoding import force_str
1213from django .utils .html import mark_safe
1314from django .utils .text import capfirst
1415from django .utils .translation import gettext as _
1516
17+ from .models import ModelChange
1618from .utils import get_history_manager_for_model , get_history_model_for_model
1719
1820SIMPLE_HISTORY_EDIT = getattr (settings , "SIMPLE_HISTORY_EDIT" , False )
@@ -22,6 +24,8 @@ class SimpleHistoryAdmin(admin.ModelAdmin):
2224 object_history_template = "simple_history/object_history.html"
2325 object_history_form_template = "simple_history/object_history_form.html"
2426
27+ max_displayed_history_change_chars = 100
28+
2529 def get_urls (self ):
2630 """Returns the additional urls used by the Reversion admin."""
2731 urls = super ().get_urls ()
@@ -83,7 +87,9 @@ def history_view(self, request, object_id, extra_context=None):
8387 # except the first (oldest) one
8488 for i in range (len (action_list ) - 1 ):
8589 delta = action_list [i ].diff_against (action_list [i + 1 ])
86- action_list [i ].history_delta_changes = delta .changes
90+ action_list [i ].history_delta_changes = [
91+ self .format_history_delta_change (change ) for change in delta .changes
92+ ]
8793
8894 context = {
8995 "title" : self .history_view_title (request , obj ),
@@ -110,6 +116,17 @@ def history_view_title(self, request, obj):
110116 else :
111117 return _ ("Change history: %s" ) % force_str (obj )
112118
119+ def format_history_delta_change (self , change : ModelChange ) -> dict :
120+ """
121+ Override this to customize the displayed values in the "Changes" column of
122+ the object history page.
123+ """
124+ return {
125+ "field" : change .field ,
126+ "old" : truncatechars (change .old , self .max_displayed_history_change_chars ),
127+ "new" : truncatechars (change .new , self .max_displayed_history_change_chars ),
128+ }
129+
113130 def response_change (self , request , obj ):
114131 if "_change_history" in request .POST and SIMPLE_HISTORY_EDIT :
115132 verbose_name = obj ._meta .verbose_name
0 commit comments