Adding additional checks to getting the queryset

This commit is contained in:
aswinm 2016-10-17 21:45:28 +05:30
parent d041a4fb1c
commit a3e44fd372

View File

@ -135,8 +135,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() queryset = viewset().get_queryset()
else:
queryset = getattr(viewset, 'queryset', None)
assert queryset is not None, '`base_name` argument not specified, and could ' \
'not automatically determine the name from the viewset, as ' \
'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):