Minor tweaks to 'lookup_value_regex' work

This commit is contained in:
Tom Christie 2014-01-13 15:37:52 +00:00
parent 4ab97843e8
commit 2911cd64ad
2 changed files with 4 additions and 5 deletions

View File

@ -2,3 +2,4 @@
* List/detail routes.
* 1.3 Support dropped, install six for <=1.4.?.
* `allow_none` for char fields
* `trailing_slash = True` --> `[^/]`, `trailing_slash = False` --> `[^/.]`, becomes simply `[^/]` and `lookup_value_regex` is added.

View File

@ -220,12 +220,10 @@ class SimpleRouter(BaseRouter):
https://github.com/alanjds/drf-nested-routers
"""
base_regex = '(?P<{lookup_prefix}{lookup_field}>{lookup_value})'
# Use `pk` as default field, unset set. Default regex should not
# consume `.json` style suffixes and should break at '/' boundaries.
lookup_field = getattr(viewset, 'lookup_field', 'pk')
try:
lookup_value = viewset.lookup_value_regex
except AttributeError:
# Don't consume `.json` style suffixes
lookup_value = '[^/.]+'
lookup_value = getattr(viewset, 'lookup_value_regex', '[^/.]+')
return base_regex.format(
lookup_prefix=lookup_prefix,
lookup_field=lookup_field,