mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-08 06:14:47 +03:00
[#3859] ability to add prefixes before lookups in per-object routes
This commit is contained in:
parent
06dd55ac1c
commit
826a47e9dd
|
@ -218,16 +218,18 @@ class SimpleRouter(BaseRouter):
|
|||
|
||||
https://github.com/alanjds/drf-nested-routers
|
||||
"""
|
||||
base_regex = '(?P<{lookup_prefix}{lookup_url_kwarg}>{lookup_value})'
|
||||
base_regex = '{pre_lookup_prefix}(?P<{lookup_prefix}{lookup_url_kwarg}>{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')
|
||||
lookup_url_kwarg = getattr(viewset, 'lookup_url_kwarg', None) or lookup_field
|
||||
lookup_value = getattr(viewset, 'lookup_value_regex', '[^/.]+')
|
||||
pre_lookup_prefix = getattr(viewset, 'pre_lookup_prefix', '')
|
||||
return base_regex.format(
|
||||
lookup_prefix=lookup_prefix,
|
||||
lookup_url_kwarg=lookup_url_kwarg,
|
||||
lookup_value=lookup_value
|
||||
lookup_value=lookup_value,
|
||||
pre_lookup_prefix=pre_lookup_prefix
|
||||
)
|
||||
|
||||
def get_urls(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user