mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-02 20:54:42 +03:00
Removed router check for deprecated '.model' attribute
This commit is contained in:
parent
60a63ffd29
commit
ba7dca893c
|
@ -130,19 +130,13 @@ 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.
|
||||||
"""
|
"""
|
||||||
# Note that `.model` attribute on views is deprecated, although we
|
|
||||||
# enforce the deprecation on the view `get_serializer_class()` and
|
|
||||||
# `get_queryset()` methods, rather than here.
|
|
||||||
model_cls = getattr(viewset, 'model', None)
|
|
||||||
queryset = getattr(viewset, 'queryset', None)
|
queryset = getattr(viewset, 'queryset', None)
|
||||||
if model_cls is None and queryset is not None:
|
|
||||||
model_cls = queryset.model
|
|
||||||
|
|
||||||
assert model_cls, '`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 model_cls._meta.object_name.lower()
|
return queryset.model._meta.object_name.lower()
|
||||||
|
|
||||||
def get_routes(self, viewset):
|
def get_routes(self, viewset):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -180,7 +180,7 @@ class TestLookupValueRegex(TestCase):
|
||||||
class TestTrailingSlashIncluded(TestCase):
|
class TestTrailingSlashIncluded(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
class NoteViewSet(viewsets.ModelViewSet):
|
class NoteViewSet(viewsets.ModelViewSet):
|
||||||
model = RouterTestModel
|
queryset = RouterTestModel.objects.all()
|
||||||
|
|
||||||
self.router = SimpleRouter()
|
self.router = SimpleRouter()
|
||||||
self.router.register(r'notes', NoteViewSet)
|
self.router.register(r'notes', NoteViewSet)
|
||||||
|
@ -195,7 +195,7 @@ class TestTrailingSlashIncluded(TestCase):
|
||||||
class TestTrailingSlashRemoved(TestCase):
|
class TestTrailingSlashRemoved(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
class NoteViewSet(viewsets.ModelViewSet):
|
class NoteViewSet(viewsets.ModelViewSet):
|
||||||
model = RouterTestModel
|
queryset = RouterTestModel.objects.all()
|
||||||
|
|
||||||
self.router = SimpleRouter(trailing_slash=False)
|
self.router = SimpleRouter(trailing_slash=False)
|
||||||
self.router.register(r'notes', NoteViewSet)
|
self.router.register(r'notes', NoteViewSet)
|
||||||
|
@ -210,7 +210,8 @@ class TestTrailingSlashRemoved(TestCase):
|
||||||
class TestNameableRoot(TestCase):
|
class TestNameableRoot(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
class NoteViewSet(viewsets.ModelViewSet):
|
class NoteViewSet(viewsets.ModelViewSet):
|
||||||
model = RouterTestModel
|
queryset = RouterTestModel.objects.all()
|
||||||
|
|
||||||
self.router = DefaultRouter()
|
self.router = DefaultRouter()
|
||||||
self.router.root_view_name = 'nameable-root'
|
self.router.root_view_name = 'nameable-root'
|
||||||
self.router.register(r'notes', NoteViewSet)
|
self.router.register(r'notes', NoteViewSet)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user