Code

Opened 7 years ago

Closed 6 years ago

#4641 closed (fixed)

newforms-admin: fix for displaying field str() value next to raw_id fields

Reported by: Matthew Flanagan <mattimustang@…> Owned by: xian
Component: contrib.admin Version: newforms-admin
Severity: Keywords: nfa-blocker
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Hi, here's a simple fix so that newforms-admin displays the current str() representation of a field next to its raw_id input widget.

regards

matthew

Index: django/contrib/admin/widgets.py
===================================================================
--- django/contrib/admin/widgets.py     (revision 5505)
+++ django/contrib/admin/widgets.py     (working copy)
@@ -65,9 +65,9 @@
         output.append('<a href="%s%s" class="related-lookup" id="lookup_id_%s" onclick="return showRelatedObjectLookupPopup(this);"> ' % \
             (related_url, url, name))
         output.append('<img src="%simg/admin/selector-search.gif" width="16" height="16" alt="Lookup"></a>' % settings.ADMIN_MEDIA_PREFIX)
+        if value:
+            output.append('&nbsp;<strong>%s</strong>' % self.rel.to.objects.get(id=value))
         return u''.join(output)
-        #if self.change: # TODO
-            #output.append('&nbsp;<strong>TODO</strong>')

 class RelatedFieldWidgetWrapper(object):
     """

Attachments (3)

4641.diff (790 bytes) - added by Karen Tracey <kmtracey@…> 7 years ago.
This patch also works for the case where the primary key field is not named 'id'
r6898_fk_raw_id_fix.diff (893 bytes) - added by brosner 6 years ago.
same patch karen provided, plus removing the TODO that this fixes. not trying to be picky ;)
4641_raw_admin_fields_display_fix.diff (3.2 KB) - added by brosner 6 years ago.
more than likely the final patch to be committed. posted here to get some last minute feedback.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 7 years ago by jkocherhans

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to xian
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Changed 7 years ago by Karen Tracey <kmtracey@…>

This patch also works for the case where the primary key field is not named 'id'

comment:2 Changed 6 years ago by brosner

  • Keywords nfa-blocker added

Changed 6 years ago by brosner

same patch karen provided, plus removing the TODO that this fixes. not trying to be picky ;)

comment:3 Changed 6 years ago by brosner

  • Triage Stage changed from Accepted to Ready for checkin

Changed 6 years ago by brosner

more than likely the final patch to be committed. posted here to get some last minute feedback.

comment:4 Changed 6 years ago by brosner

  • Resolution set to fixed
  • Status changed from new to closed

(In [7177]) newforms-admin: Fixed #4641. ForeignKeyRawIdWidget now properly displays the related object value. Thanks, Matthew Flanagan for the original patch.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.