Skip to content

Commit ba7dca8

Browse files
committed
Removed router check for deprecated '.model' attribute
1 parent 60a63ff commit ba7dca8

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

rest_framework/routers.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,13 @@ def get_default_base_name(self, viewset):
130130
If `base_name` is not specified, attempt to automatically determine
131131
it from the viewset.
132132
"""
133-
# Note that `.model` attribute on views is deprecated, although we
134-
# enforce the deprecation on the view `get_serializer_class()` and
135-
# `get_queryset()` methods, rather than here.
136-
model_cls = getattr(viewset, 'model', None)
137133
queryset = getattr(viewset, 'queryset', None)
138-
if model_cls is None and queryset is not None:
139-
model_cls = queryset.model
140134

141-
assert model_cls, '`base_name` argument not specified, and could ' \
135+
assert queryset is not None, '`base_name` argument not specified, and could ' \
142136
'not automatically determine the name from the viewset, as ' \
143137
'it does not have a `.queryset` attribute.'
144138

145-
return model_cls._meta.object_name.lower()
139+
return queryset.model._meta.object_name.lower()
146140

147141
def get_routes(self, viewset):
148142
"""

tests/test_routers.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def test_urls_limited_by_lookup_value_regex(self):
180180
class TestTrailingSlashIncluded(TestCase):
181181
def setUp(self):
182182
class NoteViewSet(viewsets.ModelViewSet):
183-
model = RouterTestModel
183+
queryset = RouterTestModel.objects.all()
184184

185185
self.router = SimpleRouter()
186186
self.router.register(r'notes', NoteViewSet)
@@ -195,7 +195,7 @@ def test_urls_have_trailing_slash_by_default(self):
195195
class TestTrailingSlashRemoved(TestCase):
196196
def setUp(self):
197197
class NoteViewSet(viewsets.ModelViewSet):
198-
model = RouterTestModel
198+
queryset = RouterTestModel.objects.all()
199199

200200
self.router = SimpleRouter(trailing_slash=False)
201201
self.router.register(r'notes', NoteViewSet)
@@ -210,7 +210,8 @@ def test_urls_can_have_trailing_slash_removed(self):
210210
class TestNameableRoot(TestCase):
211211
def setUp(self):
212212
class NoteViewSet(viewsets.ModelViewSet):
213-
model = RouterTestModel
213+
queryset = RouterTestModel.objects.all()
214+
214215
self.router = DefaultRouter()
215216
self.router.root_view_name = 'nameable-root'
216217
self.router.register(r'notes', NoteViewSet)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy