Add get_admin_url() to Model
|Reported by:||cbrand@…||Owned by:||adrian|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
From a discussion on django-users, I came up with this after contributions from two other people, one who originally got the code from elsewhere :
def get_admin_url(self): pk = getattr(self, self._meta.pk.attname) return ('django.contrib.admin.views.main.change_stage', (self._meta.app_label, self._meta.module_name, pk)) get_admin_url = models.permalink(get_admin_url)
There's nothing there that couldn't be done in the base Model class, and the fact that there were a number of people who'd seen a need for it indicates that it should at least be considered for inclusion int he base Model class.
On the downside, there's the question of what to do if the pk is None.
Also, admin is in contrib, which means that it could be omitted, but I wouldn't expect people who aren't using the admin to call the new method.
Change History (4)
comment:1 Changed 9 years ago by adrian
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Resolution set to wontfix
- Status changed from new to closed