Reversing admin URLs in Django

The AdminSite provides the following named URL patterns

Page URL name Parameters
Index index
Logout logout
Password change password_change
Password change done password_change_done
Application index page app_list app_label
Redirect to object’s page view_on_site content_type_id, object_id

Each ModelAdmin instance provides an additional set of named URLs

Page URL name Parameters
Changelist {{ app_label }}_{{ model_name }}_changelist
Add {{ app_label }}_{{ model_name }}_add
History {{ app_label }}_{{ model_name }}_history object_id
Delete {{ app_label }}_{{ model_name }}_delete object_id
Change {{ app_label }}_{{ model_name }}_change object_id

If you want to get a reference to the Change view for a particular Post object (from the posts application) in the default admin

from django.core import urlresolvers
post = Post.objects.get(pk=7)
change_url = urlresolvers.reverse('admin:posts_post_change', args=(post.id,))
comments powered by Disqus