Opened 19 years ago
Closed 11 years ago
#680 closed Bug (fixed)
get_absolute_url not being used correctly in admin interface?
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | contrib.admin | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | yes |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If a model defines a get_absolute_url(), the admin interface adds a "View on site" button. However, the URL created for the link does no use the string returned from get_absolute_url() at all.
In django/contrib/admin/views/main.py, the two places where a URL is constructed after looking get_absolute_url() both create something looking like r/1/4 where the first digit is the content type id and the latter is the object id. This looks like it is not what is intended.
Change History (3)
comment:1 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:2 by , 11 years ago
Easy pickings: | unset |
---|---|
Needs documentation: | set |
Resolution: | fixed |
Status: | closed → new |
Type: | defect → Bug |
UI/UX: | unset |
Here is one of the problems of 'requiring' such a change. Don't make this modification in urls and do the following:
- Go to admin/sites/site/
- change the domain and you will be redirected to the new mentioned domain
However if you:
- Go to admin/sites/site/
- Delete the site mentioned there
- Add a new site you want to be redirected to
There will be no change in link directed by 'View on site'.
I think if this modification is *required*, it should be (at-least) documented.
comment:3 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
This ticket is 8 years old, a lot has changed since then. Needing to include shortcut urls in your own url conf is not documented because it is not required. (I assume you are not using pre-1.0 Django.) The admin itself takes care to ensure there is a url pattern in place to handle the r/<content_type_id>/<object_id> urls it generates for the "View on Site" buttons. These requests are routed to the shortcut view noted here:
https://docs.djangoproject.com/en/1.5/ref/contrib/sites/#how-django-uses-the-sites-framework
and implemented here:
https://github.com/django/django/blob/master/django/contrib/contenttypes/views.py#L9
It isn't entirely clear to me what you are expecting differs from what is happening with respect to the "view on site" buttons, it's quite possible that view doesn't do what you expecting. If there is a bug here, it most likely needs its own bug to track it, with a current and complete description of what is going wrong...linking some current oddness to an eight-year-old ticket is just going to confuse things.
I got stung by this once recently as well.
you will need to add the following to your URLpatterns
it doesn't use the 'get_absolute_url' function as the admin interface could be on a different host name, so it wouldn't work. the '/r' shortcut would redirect you to the domain specified in the 'site' table (and it would redirect to the absolute url there I think)
re-open if this doesn't explain it