Show field values before deletion in the admin

This commit is contained in:
Alieh Rymašeŭski 2022-06-29 17:01:37 +00:00 committed by Hasan Ramezani
parent ed3ce76762
commit 7861dae4f9
3 changed files with 18 additions and 4 deletions

View file

@ -1,5 +1,9 @@
# Changes
#### Improvements
- feat: Display the diff for deleted objects in the admin ([#396](https://github.com/jazzband/django-auditlog/pull/396))
## 2.1.0 (2022-06-27)
#### Improvements

View file

@ -60,8 +60,6 @@ class LogEntryAdminMixin:
msg_short.short_description = "Changes"
def msg(self, obj):
if obj.action == LogEntry.Action.DELETE:
return "" # delete
changes = json.loads(obj.changes)
atom_changes = {}

View file

@ -1274,9 +1274,21 @@ class DiffMsgTest(TestCase):
)
def test_changes_msg_delete(self):
log_entry = self._create_log_entry(LogEntry.Action.DELETE, {})
log_entry = self._create_log_entry(
LogEntry.Action.DELETE,
{"field one": ["value before deletion", None], "field two": [11, None]},
)
self.assertEqual(self.admin.msg(log_entry), "")
self.assertEqual(
self.admin.msg(log_entry),
(
"<table>"
"<tr><th>#</th><th>Field</th><th>From</th><th>To</th></tr>"
"<tr><td>1</td><td>field one</td><td>value before deletion</td><td>None</td></tr>"
"<tr><td>2</td><td>field two</td><td>11</td><td>None</td></tr>"
"</table>"
),
)
def test_changes_msg_create(self):
log_entry = self._create_log_entry(