Simpler 'get_lookup_prefix' change

This commit is contained in:
Alan Justino da Silva 2013-08-26 14:40:59 -03:00
parent 2bec7e6d8c
commit 18bb6bcf0c

View File

@ -189,9 +189,6 @@ class SimpleRouter(BaseRouter):
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 lookup_prefix:
lookup_prefix += '_'
base_regex = '(?P<{lookup_prefix}{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, lookup_prefix=lookup_prefix) return base_regex.format(lookup_field=lookup_field, lookup_prefix=lookup_prefix)
@ -290,7 +287,7 @@ class NestedSimpleRouter(SimpleRouter):
raise RuntimeError('parent registered resource not found') raise RuntimeError('parent registered resource not found')
nested_routes = [] nested_routes = []
nest_prefix = 'nested_%i' % self.nest_count nest_prefix = 'nested_%i_' % self.nest_count
parent_lookup_regex = parent_router.get_lookup_regex(parent_viewset, nest_prefix) parent_lookup_regex = parent_router.get_lookup_regex(parent_viewset, nest_prefix)
for route in self.routes: for route in self.routes:
route_contents = route.__dict__ route_contents = route.__dict__