Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#17549 closed New feature (fixed)

Add link to open URL from URLField

Reported by: gcc Owned by: nobody
Component: contrib.admin Version: master
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 Elvard 4 years ago.
Fixed force_unicode in AdminURLFieldWidget

Download all attachments as: .zip

Change History (6)

comment:1 Changed 5 years ago by aaugustin

  • Component changed from Forms to contrib.admin
  • Needs documentation set
  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

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

comment:2 Changed 4 years ago by UloPe

  • 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:

Changed 4 years ago by Elvard

Fixed force_unicode in AdminURLFieldWidget

comment:3 Changed 4 years ago by Elvard

  • Cc tomas.ehrlich@… added
  • Version changed from 1.3 to master

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 Changed 4 years ago by Florian Apolloner <florian@…>

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

In ac2052ebc84c45709ab5f0f25e685bf656ce79bc:

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

comment:5 Changed 4 years ago by Florian Apolloner <florian@…>

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