mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-12-01 05:54:01 +03:00
Use the get_queryset from a resource if available
If a resource overrides the default get_queryset(), then ModelMixin-based classes should use it instead of returning all objects of the model of the resource. The new order of returning a queryset is: 1. self._resource.get_queryset() 2. self.resource.queryset 3. self.resource.model.objects.all()
This commit is contained in:
parent
11147ce13e
commit
231b30548b
|
@ -513,7 +513,10 @@ class ModelMixin(object):
|
||||||
"""
|
"""
|
||||||
Return the queryset for this view.
|
Return the queryset for this view.
|
||||||
"""
|
"""
|
||||||
return getattr(self.resource, 'queryset',
|
if hasattr(self._resource, 'get_queryset'):
|
||||||
|
return self._resource.get_queryset()
|
||||||
|
else:
|
||||||
|
return getattr(self._resource, 'queryset',
|
||||||
self.resource.model.objects.all())
|
self.resource.model.objects.all())
|
||||||
|
|
||||||
def get_ordering(self):
|
def get_ordering(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user