Code

Ticket #12952: django-admin-history-verbose-name.diff

File django-admin-history-verbose-name.diff, 1.8 KB (added by Alex, 4 years ago)

Initial patch, probably needs tests.

Line 
1diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
2index 43a9984..34a42a8 100644
3--- a/django/contrib/admin/options.py
4+++ b/django/contrib/admin/options.py
5@@ -553,9 +553,20 @@ class ModelAdmin(BaseModelAdmin):
6         """
7         Construct a change message from a changed object.
8         """
9+        def convert_changed_list(obj, changed_data):
10+            cls = type(obj)
11+            verbose_names = []
12+            for field in changed_data:
13+                try:
14+                    verbose_names.append(cls._meta.get_field_by_name(field)[0].verbose_name)
15+                except FieldDoesNotExist:
16+                    verbose_names.append(field)
17+            return verbose_names
18+       
19         change_message = []
20         if form.changed_data:
21-            change_message.append(_('Changed %s.') % get_text_list(form.changed_data, _('and')))
22+            change_message.append(_('Changed %s.') %
23+                get_text_list(convert_changed_list(form.instance, form.changed_data), _('and')))
24 
25         if formsets:
26             for formset in formsets:
27@@ -565,7 +576,7 @@ class ModelAdmin(BaseModelAdmin):
28                                              'object': force_unicode(added_object)})
29                 for changed_object, changed_fields in formset.changed_objects:
30                     change_message.append(_('Changed %(list)s for %(name)s "%(object)s".')
31-                                          % {'list': get_text_list(changed_fields, _('and')),
32+                                          % {'list': get_text_list(convert_changed_list(changed_object, changed_fields), _('and')),
33                                              'name': changed_object._meta.verbose_name,
34                                              'object': force_unicode(changed_object)})
35                 for deleted_object in formset.deleted_objects: