Skip to content

Commit bc880cf

Browse files
committed
Improved displaying M2M delta changes
These lists are now stringified using `str()` instead of `repr()` on each element.
1 parent 2be7045 commit bc880cf

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

simple_history/template_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ def stringify_delta_change_value(self, change: ModelChange, value: Any) -> str:
107107
:param value: Either ``change.old`` or ``change.new``, as returned by
108108
``prepare_delta_change_value()``.
109109
"""
110+
# If `value` is a list, stringify it using `str()` instead of `repr()`
111+
# (the latter of which is the default when stringifying lists)
112+
if isinstance(value, list):
113+
value = f'[{", ".join(map(str, value))}]'
114+
110115
value = conditional_escape(value)
111116
value = truncatechars_html(value, self.max_displayed_delta_change_chars)
112117
return value

simple_history/tests/tests/test_admin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ def test_history_list_contains_diff_changes_for_m2m_fields(self):
176176
expected_old_places = "[]"
177177
self.assertNotContains(response, expected_old_places)
178178
expected_new_places = (
179-
f"[<Place: Place object ({place1_pk})>,"
180-
f" <Place: Place object ({place2_pk})>]"
179+
f"[Place object ({place1_pk}), Place object ({place2_pk})]"
181180
)
182181
self.assertNotContains(response, expected_new_places)
183182

0 commit comments

Comments
 (0)