mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 11:30:12 +03:00
Optional 'lookup_prefix' on SimpleRouter.get_lookup_regex()
This commit is contained in:
parent
999056cde1
commit
f0a677a522
|
@ -184,14 +184,17 @@ 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.
|
||||
"""
|
||||
base_regex = '(?P<{lookup_field}>[^/]+)'
|
||||
if lookup_prefix:
|
||||
lookup_prefix += '_'
|
||||
|
||||
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):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user