Fix viewsets action urls with namespaces (#7287)

Use the current request's namespace to resolve action urls.
This commit is contained in:
Xavier Ordoquy 2020-04-25 09:36:10 +02:00
parent 3eef5f47f3
commit bda84372d4

View File

@ -150,6 +150,11 @@ class ViewSetMixin:
Reverse the action for the given `url_name`.
"""
url_name = '%s-%s' % (self.basename, url_name)
namespace = None
if self.request and self.request.resolver_match:
namespace = self.request.resolver_match.namespace
if namespace:
url_name = namespace + ':' + url_name
kwargs.setdefault('request', self.request)
return reverse(url_name, *args, **kwargs)