aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/routers.py
diff options
context:
space:
mode:
authorTom Christie2013-12-23 09:48:59 +0000
committerTom Christie2013-12-23 09:48:59 +0000
commit52686420f4bf866064ee88a15903665f14289394 (patch)
tree41ea7b0d4863092f996f63de14e678a1c74a7a3a /rest_framework/routers.py
parent9c41c007afc71c899306bcb02e40bdfc36b09146 (diff)
parent83b31e7ea298a8948e9a76c9b971845ea0052b3c (diff)
downloaddjango-rest-framework-52686420f4bf866064ee88a15903665f14289394.tar.bz2
Merge branch 'bennbollay-patch-1' into 2.4.0
Conflicts: .travis.yml docs/api-guide/routers.md rest_framework/compat.py tox.ini
Diffstat (limited to 'rest_framework/routers.py')
-rw-r--r--rest_framework/routers.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/rest_framework/routers.py b/rest_framework/routers.py
index 790299cc..740d58f0 100644
--- a/rest_framework/routers.py
+++ b/rest_framework/routers.py
@@ -208,18 +208,24 @@ 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.
+
+ Note that lookup_prefix is not used directly inside REST rest_framework
+ itself, but is required in order to nicely support nested router
+ implementations, such as drf-nested-routers.
+
+ https://github.com/alanjds/drf-nested-routers
"""
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):
"""