mirror of
https://github.com/jazzband/django-auditlog.git
synced 2026-03-16 22:20:26 +00:00
fixed getting field's verbose_name (#508)
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
This commit is contained in:
parent
bfb3a44296
commit
0d9fb8d6fc
3 changed files with 16 additions and 0 deletions
|
|
@ -20,6 +20,7 @@
|
|||
- fix: Fix a bug in audit log admin page when `USE_TZ=False`. ([#511](https://github.com/jazzband/django-auditlog/pull/511))
|
||||
- fix: Make sure `LogEntry.changes_dict()` returns an empty dict instead of `None` when `json.loads()` returns `None`. ([#472](https://github.com/jazzband/django-auditlog/pull/472))
|
||||
- fix: Always set remote_addr even if the request has no authenticated user. ([#484](https://github.com/jazzband/django-auditlog/pull/484))
|
||||
- fix: Fix a bug in getting field's `verbose_name` when model is not accessible. ([508](https://github.com/jazzband/django-auditlog/pull/508))
|
||||
|
||||
## 2.2.2 (2023-01-16)
|
||||
|
||||
|
|
|
|||
|
|
@ -139,6 +139,8 @@ class LogEntryAdminMixin:
|
|||
|
||||
def field_verbose_name(self, obj, field_name: str):
|
||||
model = obj.content_type.model_class()
|
||||
if model is None:
|
||||
return field_name
|
||||
try:
|
||||
model_fields = auditlog.get_model_fields(model._meta.model)
|
||||
mapping_field_name = model_fields["mapping_fields"].get(field_name)
|
||||
|
|
|
|||
|
|
@ -1651,6 +1651,19 @@ class DiffMsgTest(TestCase):
|
|||
# Re-register
|
||||
auditlog.register(SimpleModel)
|
||||
|
||||
def test_field_verbose_name(self):
|
||||
log_entry = self._create_log_entry(
|
||||
LogEntry.Action.CREATE,
|
||||
{"test": "test"},
|
||||
)
|
||||
|
||||
self.assertEqual(self.admin.field_verbose_name(log_entry, "actor"), "Actor")
|
||||
with patch(
|
||||
"django.contrib.contenttypes.models.ContentType.model_class",
|
||||
return_value=None,
|
||||
):
|
||||
self.assertEqual(self.admin.field_verbose_name(log_entry, "actor"), "actor")
|
||||
|
||||
|
||||
class NoDeleteHistoryTest(TestCase):
|
||||
def test_delete_related(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue