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:
Sean C. Farley 2012-06-29 16:11:43 -04:00
parent 11147ce13e
commit 231b30548b

View File

@ -513,8 +513,11 @@ 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'):
self.resource.model.objects.all()) return self._resource.get_queryset()
else:
return getattr(self._resource, 'queryset',
self.resource.model.objects.all())
def get_ordering(self): def get_ordering(self):
""" """