Reputation: 1824
I'm posting this because I searched stackoverflow and docs for a long time without finding an answer -- hopefully this helps somebody out.
The question is, for testing purposes, how do I find the URL that's related to admin actions for a specific model?
Admin model urls can all be found by reverse(admin:appname_modelname_*)
, where * is the action (change, delete, etc). But I couldn't find one for the admin actions, and since I was defining custom actions, I'd like to get the url.
Upvotes: 3
Views: 2075
Reputation: 21
The URL for all custom actions is reverse(admin:<appname>_<modelname>_changelist)
, but the action name is specified in the action
field of the POST data.
Upvotes: 2
Reputation: 362
This took a fair bit of digging, I couldn't find anything in the Django docs about it and I ended up having to inspect the source code of a third party library.
Essentially there are 2 URL patterns, one for bulk actions and one for object actions:
r'admin/<app_label>/<model_name>/actions/(?P<tool>\\w+)/$'
r'admin/<app_label>/<model_name>/(?P<pk>.+)/actions/(?P<tool>\\w+)/$'
The URL name pattern is <app_label>_<model_name>_actions
Therefore we can reverse the bulk view:
reverse("admin:<app_label>_<model_name>_actions", args=["foo"])
reverse("admin:<app_label>_<model_name>_actions", kwargs={"tool": "foo"})
and reverse the object view:
reverse("admin:<app_label>_<model_name>_actions", args=[1, "foo"])
reverse("admin:<app_label>_<model_name>_actions", kwargs={"pk": 1, "tool": "foo"})
Upvotes: 3
Reputation: 1824
The answer, which is hard to find, is that actions are referenced by reverse(admin:appname_modelname_changelist)
Upvotes: 0