diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
index fb5acb5..3a7a6f2 100644
a
|
b
|
class ForeignKeyRawIdWidget(forms.TextInput):
|
149 | 149 | def label_for_value(self, value): |
150 | 150 | key = self.rel.get_related_field().name |
151 | 151 | obj = self.rel.to._default_manager.get(**{key: value}) |
152 | | return ' <strong>%s</strong>' % escape(truncate_words(obj, 14)) |
| 152 | related_url = '../../../%s/%s/%s/' % (obj._meta.app_label, |
| 153 | obj._meta.object_name.lower(), obj.pk) |
| 154 | return ' <strong><a href="%s">%s</a></strong>' % (related_url, |
| 155 | escape(truncate_words(obj, 14))) |
153 | 156 | |
154 | 157 | class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): |
155 | 158 | """ |
diff --git a/tests/regressiontests/admin_widgets/models.py b/tests/regressiontests/admin_widgets/models.py
index 0c81ed3..6eed4c8 100644
a
|
b
|
from django.db import models
|
4 | 4 | from django.core.files.storage import default_storage |
5 | 5 | from django.contrib.auth.models import User |
6 | 6 | |
7 | | class MyFileField(models.FileField): |
8 | | pass |
| 7 | class MyFileField(models.FileField): |
| 8 | pass |
9 | 9 | |
10 | 10 | class Member(models.Model): |
11 | 11 | name = models.CharField(max_length=100) |
… |
… |
Currently: <a target="_blank" href="%(STORAGE_URL)salbums/hybrid_theory.jpg">alb
|
107 | 107 | >>> rel = Album._meta.get_field('band').rel |
108 | 108 | >>> w = ForeignKeyRawIdWidget(rel) |
109 | 109 | >>> print conditional_escape(w.render('test', band.pk, attrs={})) |
110 | | <input type="text" name="test" value="1" class="vForeignKeyRawIdAdminField" /><a href="../../../admin_widgets/band/?t=id" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a> <strong>Linkin Park</strong> |
| 110 | <input type="text" name="test" value="1" class="vForeignKeyRawIdAdminField" /><a href="../../../admin_widgets/band/?t=id" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a> <strong><a href="../../../admin_widgets/band/1/">Linkin Park</a></strong> |
111 | 111 | |
112 | 112 | >>> m1 = Member.objects.create(pk=1, name='Chester') |
113 | 113 | >>> m2 = Member.objects.create(pk=2, name='Mike') |
… |
… |
True
|
138 | 138 | >>> rel = Inventory._meta.get_field('parent').rel |
139 | 139 | >>> w = ForeignKeyRawIdWidget(rel) |
140 | 140 | >>> print w.render('test', core.parent_id, attrs={}) |
141 | | <input type="text" name="test" value="86" class="vForeignKeyRawIdAdminField" /><a href="../../../admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a> <strong>Apple</strong> |
| 141 | <input type="text" name="test" value="86" class="vForeignKeyRawIdAdminField" /><a href="../../../admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="/media/img/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a> <strong><a href="../../../admin_widgets/inventory/1/">Apple</a></strong> |
142 | 142 | |
143 | 143 | # see #9258 |
144 | 144 | >>> hidden = Inventory.objects.create(barcode=93, name='Hidden', hidden=True) |
145 | 145 | >>> child_of_hidden = Inventory.objects.create(barcode=94, name='Child of hidden', parent=hidden) |
146 | 146 | >>> print w.render('test', child_of_hidden.parent_id, attrs={}) |
147 | | <input type="text" name="test" value="93" class="vForeignKeyRawIdAdminField" /><a href="../../../admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_MEDIA_PREFIX)simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a> <strong>Hidden</strong> |
| 147 | <input type="text" name="test" value="93" class="vForeignKeyRawIdAdminField" /><a href="../../../admin_widgets/inventory/?t=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="/media/img/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a> <strong><a href="../../../admin_widgets/inventory/4/">Hidden</a></strong> |
148 | 148 | """ % { |
149 | 149 | 'ADMIN_MEDIA_PREFIX': settings.ADMIN_MEDIA_PREFIX, |
150 | 150 | 'STORAGE_URL': default_storage.url(''), |