Django

Code

Ticket #4641 (closed: fixed)

Opened 1 year ago

Last modified 6 months ago

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

Reported by: Matthew Flanagan <mattimustang@gmail.com> Assigned to: xian
Milestone: Component: Admin interface
Version: newforms-admin Keywords: nfa-blocker
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

4641.diff (0.8 kB) - added by Karen Tracey <kmtracey@gmail.com> on 10/15/07 11:10:22.
This patch also works for the case where the primary key field is not named 'id'
r6898_fk_raw_id_fix.diff (0.9 kB) - added by brosner on 12/17/07 16:37:36.
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 on 02/28/08 22:18:37.
more than likely the final patch to be committed. posted here to get some last minute feedback.

Change History

09/14/07 14:00:41 changed by jkocherhans

  • owner changed from nobody to xian.
  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

10/15/07 11:10:22 changed by Karen Tracey <kmtracey@gmail.com>

  • attachment 4641.diff added.

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

12/07/07 19:52:29 changed by brosner

  • keywords set to nfa-blocker.

12/17/07 16:37:36 changed by brosner

  • attachment r6898_fk_raw_id_fix.diff added.

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

12/17/07 16:37:55 changed by brosner

  • stage changed from Accepted to Ready for checkin.

02/28/08 22:18:37 changed by brosner

  • attachment 4641_raw_admin_fields_display_fix.diff added.

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

02/28/08 23:41:32 changed by brosner

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #4641 (newforms-admin: fix for displaying field str() value next to raw_id fields)




Change Properties
Action