Opened 18 years ago

Closed 17 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: 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)

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

Download all attachments as: .zip

Change History (7)

by Collin Grady <cgrady@…>, 18 years ago

comment:1 by Collin Grady <cgrady@…>, 18 years ago

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

comment:2 by Collin Grady <cgrady@…>, 18 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 Collin Grady <cgrady@…>, 18 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 Simon G. <dev@…>, 18 years ago

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

comment:5 by Collin Grady <cgrady@…>, 18 years ago

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

comment:6 by Chris Beaven, 17 years ago

Resolution: worksforme
Status: newclosed

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)

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