Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#2050 closed defect (fixed)

[patch] Display of "current value" of raw_id_admin fields wrong

Reported by: Christopher Lenz <cmlenz@…> Owned by: Adrian Holovaty
Component: contrib.admin Version: dev
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

[2827] fixed the display of the current value of a raw_id_admin configured field in the admin app. However, what is now displayed is the ID, which doesn't seem all that helpful.

If I'm not mistaken, what should be displayed here would be the __str__ of the currently associated foreign object(s). The following patch does that by access field.name instead of field.attname:

Index: django/contrib/admin/views/main.py
===================================================================
--- django/contrib/admin/views/main.py  (revision 510)
+++ django/contrib/admin/views/main.py  (working copy)
@@ -143,9 +143,10 @@
             return self._display
         except AttributeError:
             if isinstance(self.field.rel, models.ManyToOneRel):
-                self._display = getattr(self.original, self.field.attname)
+                print `self.original`, `self.field.attname`
+                self._display = getattr(self.original, self.field.name)
             elif isinstance(self.field.rel, models.ManyToManyRel):
-                self._display = ", ".join([str(obj) for obj in getattr(self.original, self.field.attname).all()])
+                self._display = ", ".join([str(obj) for obj in getattr(self.original, self.field.name).all()])
             return self._display
 
     def __repr__(self):

Change History (2)

comment:1 by Adrian Holovaty, 18 years ago

I assume the print statement in the patch was left in erroneously, right?

comment:2 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: newclosed

(In [3018]) Fixed #2050 -- Fixed raw_id_admin display in admin. Thanks, Christopher Lenz

Note: See TracTickets for help on using tickets.
Back to Top