Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#17549 closed New feature (fixed)

Add link to open URL from URLField

Reported by: Chris Wilson Owned by: nobody
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: tomas.ehrlich@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes


It's useful for URLField to give you a way to open the URL; otherwise you might as well use a CharField.

class URLFieldWidgetWithLink(AdminURLFieldWidget):
    def render(self, name, value, attrs=None):
        html = AdminURLFieldWidget.render(self, name, value, attrs=attrs)

        if value is not None:
            final_attrs = dict(href=value, target='_blank')
            html += " <a %s>(open)</a>" % attributes_to_str(final_attrs)
        from django.utils.safestring import mark_safe
        return mark_safe(html)

class DocumentAdmin(admin.ModelAdmin):
    formfield_overrides = {
        django_fields.URLField: {'widget': URLFieldWidgetWithLink},

Attachments (1)

17549.patch (3.5 KB ) - added by Tomáš Ehrlich 12 years ago.
Fixed force_unicode in AdminURLFieldWidget

Download all attachments as: .zip

Change History (6)

comment:1 by Aymeric Augustin, 12 years ago

Component: Formscontrib.admin
Needs documentation: set
Needs tests: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

I suppose the code in the ticket description is the patch; a unified diff would be much easier to apply...

comment:2 by Ulrich Petri, 12 years ago

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

I've turned the ad-hoc code in the description into a proper patch for AdminURLFieldWidget and added tests as well as a short mention of this new feature in the docs.

Code at:

by Tomáš Ehrlich, 12 years ago

Attachment: 17549.patch added

Fixed force_unicode in AdminURLFieldWidget

comment:3 by Tomáš Ehrlich, 12 years ago

Cc: tomas.ehrlich@… added
Version: 1.3master

Pull request has broken tests with latest checkout of Django:

NameError: global name 'force_unicode' is not defined

in django/contrib/admin/

I've just renamed force_unicode to force_text and tests passed.

comment:4 by Florian Apolloner <florian@…>, 12 years ago

Resolution: fixed
Status: newclosed

In ac2052ebc84c45709ab5f0f25e685bf656ce79bc:

Fixed #17549 -- Added a clickable link for URLFields in admin change list.

comment:5 by Florian Apolloner <florian@…>, 12 years ago

In f12fa7750c95cafa3a317be6a62ed3a2f53caf3c:

[1.5.X] Fixed #17549 -- Added a clickable link for URLFields in admin change list.

Backport of ac2052ebc84c45709ab5f0f25e685bf656ce79bc from master.

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