15

I would like to make a link that would take the user to a particular item in the admin site (assuming they have the correct permissions).

Something like: https://mysite/admin/app/model/id/

Can this be done with reverse?

Timmy O'Mahony
  • 53,000
  • 18
  • 155
  • 177
Alex
  • 1,891
  • 3
  • 23
  • 39
  • see http://stackoverflow.com/questions/694477/getting-django-admin-url-for-an-object/2930241#2930241 – second Nov 08 '11 at 22:07
  • 1
    @second - that question is from the good old Django 1.0 days, so there's quite a lot of noise. I've tried to summarise the information below. – Alasdair Nov 08 '11 at 22:19

1 Answers1

22

You can get the url in the view, using reverse,

object_change_url = reverse('admin:myapp_mymodel_change', args=(obj.id,))

Or in the template, using the url tag

{% url 'admin:myapp_mymodel_change' obj.id %}

or

{% load admin_urls %}
{% url opts|admin_urlname:'change' obj.id %}">

Note the above url tag syntax is for Django >= 1.5.

For more information, see the Django docs on reversing admin urls.

Alasdair
  • 298,606
  • 55
  • 578
  • 516