ModelAdmin hook for customising the "show on site" button
As Simon Willison suggested on django developers:
Further thinking about get_absolute_url. At the moment, the main
reason it's a standard in Django is that it is used by
django.contrib.admin to display the "show on site" button inside the
admin interface.
This mechanism isn't very robust. Admin sites are often run on
different subdomains from the rest of the site, which means that
get_absolute_url on its own isn't enough - instead, we have to go
through the whole /r/{{ content-type-id }}/{{ object-id }}/ palaver
which attempts to figure out the site based on ForeignKey(Site)
properties on the model, or by using the default site from SITE_ID.
It would make a lot more sense to allow ModelAdmin subclasses to
define that behaviour themselves, for example:
class ArticleAdmin(admin.ModelAdmin):
...
def show_on_site(self, obj):
return 'http://livesite.example.com' + obj.get_url_path()
We could even support "show_on_site = True" as meaning "include the
show on site link, using cleverness to figure out the link" whereas
show_on_site = a_callable means "call this function to figure out the
URL for that link".
Change History
(18)
Triage Stage: |
Unreviewed → Accepted
|
Cc: |
almir@… added
|
Has patch: |
set
|
Owner: |
changed from nobody to Ivan Giuliani
|
Severity: |
→ Normal
|
Type: |
→ New feature
|
Easy pickings: |
unset
|
Patch needs improvement: |
set
|
Owner: |
changed from Ivan Giuliani to Unai Zalakain
|
Patch needs improvement: |
unset
|
Status: |
new → assigned
|
Patch needs improvement: |
set
|
Patch needs improvement: |
unset
|
Patch needs improvement: |
set
|
Patch needs improvement: |
unset
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
i wonder, am i on the right track?