Opened 13 years ago
Closed 12 years ago
#18072 closed Cleanup/optimization (fixed)
ChangeList shouldn't use hardcoded urls
Reported by: | Mikhail Korobov | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 1.4 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Some urls are still hardcoded in admin: ChangeList.url_for_result returns implicit relative url https://code.djangoproject.com/browser/django/trunk/django/contrib/admin/views/main.py#L377
Noticed this while implementing custom AdminSite that shows a changelist of one of the models as an index page (edit links were incorrect):
class RestaurantPanel(admin.AdminSite): main_model = None @never_cache def index(self, request, extra_context=None): model_admin = self._registry[self.main_model] return model_admin.changelist_view(request, extra_context)
This ChangeList subclass fixed the issue for me:
class FixedChangeList(ChangeList): def url_for_result(self, result): admin_name = self.model_admin.admin_site.name pk = getattr(result, self.pk_attname) return reverse("%s:%s_%s_change" % ( admin_name, self.opts.app_label, self.opts.module_name ), args=[pk])
Change History (4)
comment:1 by , 13 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 13 years ago
comment:3 by , 12 years ago
Type: | Uncategorized → Cleanup/optimization |
---|
comment:4 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Ran into the same problem here. There're also other instances of hardcoded urls in the ModelAdmin.response_add and ModelAdmin.response_change, which I think can go into the same fix.