Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For a django model, how can I get the django admin URL to add another, or list objects, etc.?

As much as I love the django documentation, the section on bookmarklets in the admin is strangely vague.

My question is this: If I'm in a view and I have a django model (or, in some cases, an actual object), how can I get to the relevant admin pages for that model (or object)? If I have the object coconut_transportation.swallow.objects.all()[34], how can I jump right to the admin page to edit that particular swallow?

Likewise, how can I get the URL for the admin page to add another swallow?

like image 398
jMyles Avatar asked Sep 03 '25 05:09

jMyles


1 Answers

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#reversing-admin-urls

obj = coconut_transportation.swallow.objects.all()[34]

# list url
url = reverse("admin:coconut_transportation_swallow_changelist")

# change url
url = reverse("admin:coconut_transportation_swallow_change", args=[obj.id])

# add url
url = reverse("admin:coconut_transportation_swallow_add")
like image 138
Yuji 'Tomita' Tomita Avatar answered Sep 04 '25 23:09

Yuji 'Tomita' Tomita