Opened 15 years ago
Last modified 14 years ago
#11163 closed
admin ForeignKeyRawIdWidget contains incorrect link when used in change list view — at Version 1
Reported by: | 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 (last modified by )
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:
while the url from the edit form is like this:
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
(reformatted description)