Description
If you attempt to attach DjangoObjectActions to a model that has a primary key that is neither hex nor decimal, a NoReverseMatch
exception is thrown.
The problem is this code in _get_action_urls()
:
# change, supports pks that are numbers or uuids
url(r'^(?P<pk>[0-9a-f\-]+)/actions/(?P<tool>\w+)/$',
This seems arbitrary, considering that we're creating a new custom URL space and all primary keys have to be already URL-compatible.
I fixed my use case by relaxing the pattern:
url(r'^(?P<pk>[\w\\-]+)/actions/(?P<tool>\w+)/$',
...which doesn't appear to have any negative consequences.
Recommendation:
-
Relax the regex; or
-
Provide a mechanism to easily override the default assumptions about primary key regex; or
-
Make it easier to add extra urls to the results of this function. I tried to create a subclass that appended another URL pattern to the results of
super(DjangoObjectActions, self)._get_action_urls()
but I needed a bunch of context that's created within that method, so it was just easier to copy the entire method into the subclass and change the regex.