change router to take base name from model along with queryset

This commit is contained in:
Mohit Mittal 2016-10-05 00:57:01 +00:00
parent c5b4be701a
commit 0e039402b2

View File

@ -133,12 +133,14 @@ class SimpleRouter(BaseRouter):
it from the viewset.
"""
queryset = getattr(viewset, 'queryset', None)
assert queryset is not None, '`base_name` argument not specified, and could ' \
model = getattr(viewset, 'model', None)
assert ((queryset is not None) or (model 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()
model = model if model is not None else queryset.model
return model._meta.object_name.lower()
def get_routes(self, viewset):
"""