aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Justino2013-12-10 17:14:17 -0200
committerAlan Justino2013-12-10 17:14:17 -0200
commitd3a118c728729f63f7e7c7c39b62a7932ca06391 (patch)
tree7b66629127882c646f5366cbaa98a38ac9168afc
parent462c5e3d0defaceaf4b5b946d4a9f761a56b701a (diff)
downloaddjango-rest-framework-d3a118c728729f63f7e7c7c39b62a7932ca06391.tar.bz2
SimpleRouter.get_lookup_regex got lookup_prefix
This allows @alanjds/drf-nested-routers to not duplicate/monkeypatch work made here
-rw-r--r--rest_framework/routers.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/rest_framework/routers.py b/rest_framework/routers.py
index 3fee1e49..7915991d 100644
--- a/rest_framework/routers.py
+++ b/rest_framework/routers.py
@@ -184,18 +184,18 @@ class SimpleRouter(BaseRouter):
bound_methods[method] = action
return bound_methods
- def get_lookup_regex(self, viewset):
+ def get_lookup_regex(self, viewset, lookup_prefix=''):
"""
Given a viewset, return the portion of URL regex that is used
to match against a single instance.
"""
if self.trailing_slash:
- base_regex = '(?P<{lookup_field}>[^/]+)'
+ base_regex = '(?P<{lookup_prefix}{lookup_field}>[^/]+)'
else:
# Don't consume `.json` style suffixes
- base_regex = '(?P<{lookup_field}>[^/.]+)'
+ base_regex = '(?P<{lookup_prefix}{lookup_field}>[^/.]+)'
lookup_field = getattr(viewset, 'lookup_field', 'pk')
- return base_regex.format(lookup_field=lookup_field)
+ return base_regex.format(lookup_field=lookup_field, lookup_prefix=lookup_prefix)
def get_urls(self):
"""