I’m a little thrown by this. I have the following code, which works perfectly well:
urlresolvers.reverse('admin:cards_card_change', args=([92]))
To further my understanding, I wanted to try rewriting the line as:
urlresolvers.reverse('admin:cards_card_change', kwargs={'object_id':92})
as seemingly suggested by the documentation on reversing admin views (I’m using Django 1.4).
However, this doesn’t seem to match anything at all. Why not? I tried looking in the django source code for answers, but couldn’t find the view used for change, so links to the relevant module there would be really helpful as well!
The
urlpatternof the change view is in admin/options.py:You could find that it dispatches a request to the
change_viewmethod of theModelAdmininstance. Thechange_viewmethod also resides in admin/options.py:It does accept a parameter
object_id.The reason of the missing match of
reverseis that theurlpatternabove does not accept named parameter, if you change it to something likeThe
urlresolvers.reverse('admin:cards_card_change', kwargs={'object_id':92})should work.I’ve no idea whether it was intended to avoid some edge cases or it’s just a bug and there’s already a ticket fixing this. I’ll check it later.