SimpleRouter.get_lookup_regex got lookup_prefix

This allows @alanjds/drf-nested-routers to not duplicate/monkeypatch work made here
This commit is contained in:
Alan Justino 2013-12-10 17:14:17 -02:00
parent 462c5e3d0d
commit d3a118c728

View File

@ -184,18 +184,18 @@ class SimpleRouter(BaseRouter):
bound_methods[method] = action bound_methods[method] = action
return bound_methods 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 Given a viewset, return the portion of URL regex that is used
to match against a single instance. to match against a single instance.
""" """
if self.trailing_slash: if self.trailing_slash:
base_regex = '(?P<{lookup_field}>[^/]+)' base_regex = '(?P<{lookup_prefix}{lookup_field}>[^/]+)'
else: else:
# Don't consume `.json` style suffixes # 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') 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): def get_urls(self):
""" """