Opened 12 years ago

Closed 10 years ago

#3015 closed enhancement (worksforme)

[patch] Small change to django.contrib.admin.urls to allow permalink() usage

Reported by: Collin Grady <cgrady@…> 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: UI/UX:


The current 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)

admin-urls-permalink-compatible.patch (1.8 KB) - added by Collin Grady <cgrady@…> 12 years ago.

Download all attachments as: .zip

Change History (7)

Changed 12 years ago by Collin Grady <cgrady@…>

comment:1 Changed 12 years ago by Collin Grady <cgrady@…>

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':})
    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 :)

comment:2 Changed 12 years ago by Collin Grady <cgrady@…>

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__(})

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 Changed 12 years ago by Collin Grady <cgrady@…>

Didn't realize this before, but the last entry in the dict could be changed to

'object_id': getattr(self,

comment:4 Changed 11 years ago by Simon G. <dev@…>

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

comment:5 Changed 11 years ago by Collin Grady <cgrady@…>

What do I need to improve in the patch? :)

comment:6 Changed 10 years ago by Chris Beaven

Resolution: worksforme
Status: newclosed

Permalink doesn't fail, you just need to pass the arguments positionally at the moment:

    def get_admin_url(self):
        return 'django.contrib.admin.views.main.change_stage', [
            self._meta.app_label, self._meta.module_name,

(and changing it probably isn't worth it with newforms-admin on the way)

Note: See TracTickets for help on using tickets.
Back to Top