views:

244

answers:

1

I know the link template to reach an object is like following:

"{{ domain }}/{{ admin_dir }}/{{ appname }}/{{ modelname }}/{{ pk }}"

Is there a way built-in to get a permalink for an object?

from django.contrib import admin

def get_admin_permalink(instance, admin_site=admin.site):
    # returns admin URL for instance change page
    raise NotImplemented

EDIT

It seems in v1.1 admin has named URLs. Unfortunately it's not yet released.

+1  A: 

1.1 is out, the doc is right here: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#admin-reverse-urls http://docs.djangoproject.com/en/dev/ref/templates/builtins/#url

I also used it a bit, the admin namespace will have to be specified whenever you are fetching an existing admin url.

# in urls.py, assuming you have a customized view
url(r'foo/$', 'foo', name='foo_index'),

# in the template, to get the admin url
{% url admin:foo_index %}

In 1.1, whenever an admin url is fetched, you'll have to specify the 'admin' namespace.

Thierry Lam