Code

Ticket #1054: magic_removal-admin_list_repr_to_str-2.diff

File magic_removal-admin_list_repr_to_str-2.diff, 1.4 KB (added by Tom Tobin <korpios@…>, 8 years ago)

Fix admin_list using __repr__ where it should use __str__ (fresh for recent changes)

Line 
1Index: db/models/options.py
2===================================================================
3--- db/models/options.py        (revision 2113)
4+++ db/models/options.py        (working copy)
5@@ -209,7 +209,7 @@
6         save_on_top=False, list_select_related=False):
7         self.fields = fields
8         self.js = js or []
9-        self.list_display = list_display or ['__repr__']
10+        self.list_display = list_display or ['__str__']
11         self.list_filter = list_filter or []
12         self.date_hierarchy = date_hierarchy
13         self.save_as, self.ordering = save_as, ordering
14Index: contrib/admin/templatetags/admin_list.py
15===================================================================
16--- contrib/admin/templatetags/admin_list.py    (revision 2113)
17+++ contrib/admin/templatetags/admin_list.py    (working copy)
18@@ -76,8 +76,8 @@
19         except models.FieldDoesNotExist:
20             # For non-field list_display values, check for the function
21             # attribute "short_description". If that doesn't exist, fall
22-            # back to the method name. And __repr__ is a special-case.
23-            if field_name == '__repr__':
24+            # back to the method name. And __str__ is a special-case.
25+            if field_name == '__str__':
26                 header = lookup_opts.verbose_name
27             else:
28                 func = getattr(cl.model, field_name) # Let AttributeErrors propogate.