From 231b30548b28a31eeac03f4d12b9dd1f9f63a02f Mon Sep 17 00:00:00 2001 From: "Sean C. Farley" Date: Fri, 29 Jun 2012 16:11:43 -0400 Subject: [PATCH] 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() --- djangorestframework/mixins.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/djangorestframework/mixins.py b/djangorestframework/mixins.py index 6c8f8179d..fc3753b26 100644 --- a/djangorestframework/mixins.py +++ b/djangorestframework/mixins.py @@ -513,8 +513,11 @@ class ModelMixin(object): """ Return the queryset for this view. """ - return getattr(self.resource, 'queryset', - self.resource.model.objects.all()) + if hasattr(self._resource, 'get_queryset'): + return self._resource.get_queryset() + else: + return getattr(self._resource, 'queryset', + self.resource.model.objects.all()) def get_ordering(self): """