mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
Minor tweaks to 'lookup_value_regex' work
This commit is contained in:
parent
4ab97843e8
commit
2911cd64ad
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user