Opened 15 years ago

Last modified 14 years ago

#11163 closed

admin ForeignKeyRawIdWidget contains incorrect link when used in change list view — at Initial Version

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

Description

When the user specifies in their admin.py that a field is both editable and a raw_id, like this:

list_editable = ('owner',)
raw_id_fields = ('owner',)

the ForeignKeyRawIdWidget is used in the change list view for that field. However, the code in the ForeignKeyRawIdWidget's render() method is hardcoded to be called from the edit form, with the following code:

related_url = '../../../%s/%s/' % (self.rel.to._meta.app_label, self.rel.to._meta.object_name.lower())

When called from the change list, the url has one less entry than when called from the edit form. As a result, the link is wrong when called from the change list. For example, the url for the changelist is something like this:

http://mysite.com/admin/taskmanager/task/

while the url from the edit form is like this:

http://mysite.com/admin/taskmanager/task/1

So when used in the change list, the raw id widget's link ends up pointing to http://mysite.com/auth/user/?t=id rather than http://mysite.com/admin/auth/user/?t=id

Change History (0)

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