AdminURLFieldWidget question

11 views
Skip to first unread message

Mike Dewhirst

unread,
Mar 26, 2017, 3:32:58 AM3/26/17
to Django users
How can I manipulate the link in an Admin URLField so it uses the normal
HTML hyperlink attributes?

I have a substance with ingredients in a self m2m relationship and I
want the ingredients displayed to carry a link to open themself in
another substance page.

IOW, I want to use the substance.name (ie, ingredient name) instead of
substance.id in the URL.

Also, I don't need the user to see the input ("Change") part of the
field because that is always done by the software.

I guess the answer is to sub-class the AdminURLFieldWidget and use that
via ...

formfield_overrides = {

URLField: {'widget': myAdminURLFieldWidget},

}


However, I'm a bit lost in making it happen. Where do I learn more?

Thanks

Mike


Mike Dewhirst

unread,
Mar 26, 2017, 6:51:49 PM3/26/17
to Django users
Declaring myAdminURLFieldWidget outside the ModelAdmin class is the answer!
Reply all
Reply to author
Forward
0 new messages