Skip to content

Commit afb3827

Browse files
committed
Admin history changes displays field verbose_name
This should be more readable to website users, in contrast to displaying the field's name from the code.
1 parent 06ffe13 commit afb3827

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

simple_history/admin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ def format_history_delta_change(self, change: ModelChange) -> dict:
121121
Override this to customize the displayed values in the "Changes" column of
122122
the object history page.
123123
"""
124+
field_meta = self.model._meta.get_field(change.field)
124125
return {
125-
"field": change.field,
126+
"field": capfirst(field_meta.verbose_name),
126127
"old": truncatechars(change.old, self.max_displayed_history_change_chars),
127128
"new": truncatechars(change.new, self.max_displayed_history_change_chars),
128129
}

simple_history/templates/simple_history/_object_history_list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<ul>
4747
{% for change in action.history_delta_changes %}
4848
<li>
49-
<code>{{ change.field }}</code>:
49+
<strong>{{ change.field }}:</strong>
5050
{{ change.old }}
5151
{# Add some spacing, and prevent having the arrow point to the edge of the page if `new` is wrapped #}
5252
&nbsp;&rarr;&nbsp;&nbsp;{{ change.new }}

simple_history/tests/tests/test_admin.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,27 +98,27 @@ def test_history_list_contains_diff_changes(self):
9898
self.assertContains(response, "Changes")
9999
# The poll hasn't had any of its fields changed after creation,
100100
# so these values should not be present
101-
self.assertNotContains(response, "question")
101+
self.assertNotContains(response, "Question")
102102
self.assertNotContains(response, "why?")
103-
self.assertNotContains(response, "pub_date")
103+
self.assertNotContains(response, "Date published")
104104

105105
poll.question = "how?"
106106
poll.save()
107107
response = self.client.get(poll_history_url)
108-
self.assertContains(response, "question")
108+
self.assertContains(response, "Question")
109109
self.assertContains(response, "why?")
110110
self.assertContains(response, "how?")
111-
self.assertNotContains(response, "pub_date")
111+
self.assertNotContains(response, "Date published")
112112

113113
poll.question = "when?"
114114
poll.pub_date = parse_datetime("2024-04-04 04:04:04")
115115
poll.save()
116116
response = self.client.get(poll_history_url)
117-
self.assertContains(response, "question")
117+
self.assertContains(response, "Question")
118118
self.assertContains(response, "why?")
119119
self.assertContains(response, "how?")
120120
self.assertContains(response, "when?")
121-
self.assertContains(response, "pub_date")
121+
self.assertContains(response, "Date published")
122122
self.assertContains(response, "2021-01-01 10:00:00")
123123
self.assertContains(response, "2024-04-04 04:04:04")
124124

@@ -131,7 +131,7 @@ def test_history_list_doesnt_contain_too_long_diff_changes(self):
131131
poll.save()
132132

133133
response = self.client.get(get_history_url(poll))
134-
self.assertContains(response, "question")
134+
self.assertContains(response, "Question")
135135
expected_num_chars = SimpleHistoryAdmin.max_displayed_history_change_chars - 1
136136
self.assertContains(response, f"{'A' * expected_num_chars}…")
137137
self.assertContains(response, f"{'B' * expected_num_chars}…")

0 commit comments

Comments
 (0)