#19002 closed Uncategorized (needsinfo)
Hardcoded url in admin
Reported by: | Riccardo Di Virgilio | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 1.4 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
in django.contrib.admin.sites there are a lot or reverse url called with hard coded "admin:"
for example reverse('admin:%s_%s_changelist'
i've got multiple admin sites with different names, and without this patch the link do not works at all...
they must be called with admin_site.name attribute instead... i attached a diff file
Attachments (1)
Change History (5)
by , 12 years ago
Attachment: | sites.diff added |
---|
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Component: | Uncategorized → contrib.admin |
---|
comment:3 by , 12 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
What do you mean with "the link do not works at all"? Where do these URLs point to? What do you mean with "I've got multiple admin sites with different names"? Are they AdminSite instances?
Referencing the admin docs (https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#multiple-admin-sites-in-the-same-urlconf) and the namespaced URLs docs (https://docs.djangoproject.com/en/1.4/topics/http/urls/#defining-url-namespaces and https://docs.djangoproject.com/en/1.4/topics/http/urls/#url-namespaces) all the admin app instances share the same application namespace ('admin'
) and what allows to differenciates among their URL namespaces when reversin named URLs with reverse() (or equivalente url template tag) is the value of the current_app argument.
In the case of the admin app it's the AdminSite.name
value which is the one you can control and which is the one we are passed as current_app in all calls to reverse().
comment:4 by , 11 years ago
Actually I believe this is a bad pattern.
When you use url('admin', include(admin.site.urls)), since admin.site is a AdminSite instance and the urls property has the following code:
@property
def urls(self):
return self.get_urls(), self.app_name, self.name
This code makes the namespace dynamic by using self.app_name, but further on the code it uses the admin namespace harcoded, makes no sense to me.
It would be better to use something like reverse(self.app_name + ':%s_%s_changelist')
I've come to this when I was trying to extend the admin behavior. I've created an instance of AdminSite with a different namespace and is impossible to use it like this.
Is there any other reason for this to be hardcoded? AdminSite becomes irrelevant outside of the admin context the way it is right now and the same happens on ModelAdmin.
sorry i've made a diff from an older version of django... just watch the reverse url part of the diff