#11775 closed New feature (fixed)
ABSOLUTE_URL_OVERRIDES doesn't work for the majority of contrib models
Reported by: | Jukka Välimaa | Owned by: | Jukka Välimaa |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Release blocker | Keywords: | |
Cc: | Jukka Välimaa | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
At the moment, ABSOLUTE_URL_OVERRIDES is used to override get_absolute_url methods. However, most models in django.contrib don't have the get_absolute_url method in the first place, and so ABSOLUTE_URL_OVERRIDES does nothing to them. This means that you can't have links from unmodified admin pages of these model objects to the page that represents the model object in the application. If there is code that relies on getting the url to object by get_absolute_url, there needs to be separate code to handle these model objects.
The reporter of this ticket came across both of these problems when wanting to link to the application page of a group (contrib.auth.models.Group) from admin, and from a general search.
Proposed solution: Make it possible for ABSOLUTE_URL_OVERRIDES to insert a function as get_absolute_url method of a model class, rather than only overriding existing methods. (Design decision needed on this one, I think)
Attachments (1)
Change History (16)
comment:1 by , 15 years ago
Status: | new → assigned |
---|
comment:2 by , 15 years ago
Needs tests: | set |
---|---|
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 15 years ago
Added two tests for ABSOLUTE_URL_OVERRIDES feature, removed use of currying.
comment:4 by , 15 years ago
Cc: | added |
---|
comment:5 by , 15 years ago
Needs tests: | unset |
---|---|
Patch needs improvement: | unset |
comment:6 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:7 by , 14 years ago
Easy pickings: | unset |
---|---|
Patch needs improvement: | set |
patch.diff fails to apply cleanly on to trunk
comment:9 by , 11 years ago
Can we deprecate ABSOLUTE_URL_OVERRIDES instead? Currently get_absolute_url
and related features create lots of cross-layer coupling.
comment:10 by , 10 years ago
I was going to suggest we could replace settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' % (opts.app_label, opts.model_name)
with URL reversing; something like reverse('%s.%s-absolute-url') % (opts.app_label, opts.model_name)
, but this would force people to rename their URLs in order to match the convention.
Given the lack of interest in this ticket, maybe it would be better to simply "won't fix" it and remove it when we come up with a solution for #8264 "Replace get_absolute_url with more sane alternative".
comment:11 by , 10 years ago
Patch needs improvement: | unset |
---|---|
Severity: | Normal → Release blocker |
comment:12 by , 10 years ago
Tim, I reviewed PR. The changes look good and work for me.
I agree, the regression should be fixed for as long as ABSOLUTE_URL_OVERRIDES is part of Django.
comment:13 by , 10 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:14 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Seems like a reasonable idea to me, and the implementation is relatively simple.
One problem with the patch - it needs tests. The fact that there aren't any existing tests for ABSOLUTE_URL_OVERRIDES doesn't excuse you from writing some. If you want to win extra Brownie points, you should take the opportunity to write a full test suite for the entire ABSOLUTE_URL_OVERRIDES feature, not just the bit you added.
I'm also interested to see if the use of currying can be removed altogether. While currying is a neat trick, it doesn't seem necessary in this case. The historical use is actually more computationally intensive than it should be. All we are doing here is substituting cls.get_absolute_url with the appropriate override. We don't need to re-evaluate ABSOLUTE_URL_OVERRIDES on every call to get_absolute_url.
As prior warning: there is also a lingering background issue surrounding this idea and its intersection with ReplacingGetAbsoluteUrl. No formal decisions have been made, but if a decision *is* made, it will impact on this ticket and patch.