Ticket #7923: ticket7923.patch

File ticket7923.patch, 2.4 KB (added by mrts, 9 years ago)

Patch with test.

  • django/contrib/admin/widgets.py

    diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
    index fb5acb5..3a7a6f2 100644
    a b class ForeignKeyRawIdWidget(forms.TextInput): 
    149149    def label_for_value(self, value):
    150150        key = self.rel.get_related_field().name
    151151        obj = self.rel.to._default_manager.get(**{key: value})
    152         return '&nbsp;<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 '&nbsp;<strong><a href="%s">%s</a></strong>' % (related_url,
     155                escape(truncate_words(obj, 14)))
    153156
    154157class ManyToManyRawIdWidget(ForeignKeyRawIdWidget):
    155158    """
  • tests/regressiontests/admin_widgets/models.py

    diff --git a/tests/regressiontests/admin_widgets/models.py b/tests/regressiontests/admin_widgets/models.py
    index 0c81ed3..0fc3dc2 100644
    a b from django.db import models 
    44from django.core.files.storage import default_storage
    55from django.contrib.auth.models import User
    66
    7 class MyFileField(models.FileField): 
    8     pass 
     7class MyFileField(models.FileField):
     8    pass
    99
    1010class Member(models.Model):
    1111    name = models.CharField(max_length=100)
    Currently: <a target="_blank" href="%(STORAGE_URL)salbums/hybrid_theory.jpg">alb 
    107107>>> rel = Album._meta.get_field('band').rel
    108108>>> w = ForeignKeyRawIdWidget(rel)
    109109>>> 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>&nbsp;<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>&nbsp;<strong><a href="../../../admin_widgets/band/1/">Linkin Park</a></strong>
    111111
    112112>>> m1 = Member.objects.create(pk=1, name='Chester')
    113113>>> m2 = Member.objects.create(pk=2, name='Mike')
Back to Top