Opened 19 years ago
Closed 18 years ago
#3015 closed enhancement (worksforme)
[patch] Small change to django.contrib.admin.urls to allow permalink() usage
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | contrib.admin | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | yes |
| Easy pickings: | no | UI/UX: | no |
Description
The current urls.py for the admin app doesn't name some of the params, so trying to use permalink() with it fails - as this is useful in some situations, and doesn't harm the function of the existing app at all, I think it should be updated so it does work with it.
Attachments (1)
Change History (7)
by , 19 years ago
| Attachment: | admin-urls-permalink-compatible.patch added |
|---|
comment:1 by , 19 years ago
comment:2 by , 19 years ago
Hmm, might be possible to make this a generalized and always-there function on models?
def get_admin_url(self):
return ('django.contrib.admin.views.main.change_stage', None, {'app_label': self._meta.app_label, 'model_name': self._meta.module_name, 'object_id': self.__getattribute__(self._meta.pk.attname)})
That seems to pick up app/model/id values instantly - or would it need a check to see if there even is a pk?
comment:3 by , 19 years ago
Didn't realize this before, but the last entry in the dict could be changed to
'object_id': getattr(self, self._meta.pk.attname)
comment:4 by , 19 years ago
| Patch needs improvement: | set |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:6 by , 18 years ago
| Resolution: | → worksforme |
|---|---|
| Status: | new → closed |
Permalink doesn't fail, you just need to pass the arguments positionally at the moment:
@models.permalink def get_admin_url(self): return 'django.contrib.admin.views.main.change_stage', [ self._meta.app_label, self._meta.module_name, getattr(self, self._meta.pk.attname) ]
(and changing it probably isn't worth it with newforms-admin on the way)
Afterthought, as an example you can do something like this with this change applied:
def get_admin_url(self): return ('django.contrib.admin.views.main.change_stage', None, {'app_label': 'blog', 'model_name': 'entry', 'object_id': self.id}) get_admin_url = permalink(get_admin_url)It might be possible to grab that info through _meta or such also, but I haven't played with that much :)