This commit is contained in:
Aswin Murugesh 2017-04-20 15:04:52 +00:00 committed by GitHub
commit 14db6755d5

View File

@ -134,12 +134,14 @@ class SimpleRouter(BaseRouter):
If `base_name` is not specified, attempt to automatically determine If `base_name` is not specified, attempt to automatically determine
it from the viewset. it from the viewset.
""" """
if hasattr(viewset, 'get_queryset'):
queryset = viewset().get_queryset()
else:
queryset = getattr(viewset, 'queryset', None) queryset = getattr(viewset, 'queryset', None)
assert queryset is not None, '`base_name` argument not specified, and could ' \ assert queryset is not None, '`base_name` argument not specified, and could ' \
'not automatically determine the name from the viewset, as ' \ 'not automatically determine the name from the viewset, as ' \
'it does not have a `.queryset` attribute.' 'it does not have a `.queryset` attribute.'
return queryset.model._meta.object_name.lower() return queryset.model._meta.object_name.lower()
def get_routes(self, viewset): def get_routes(self, viewset):