From 02b2020995c6a59063fbab665bf0abac75244439 Mon Sep 17 00:00:00 2001 From: "Sean C. Farley" Date: Mon, 5 Mar 2012 20:13:26 -0500 Subject: [PATCH] Handle a callable queryset in ModelMixin To allow queryset's that may depend on a value obtained from a middleware or somewhere else that can change the result of the query, accept and process a callable queryset in addition to previous behavior. --- djangorestframework/mixins.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/djangorestframework/mixins.py b/djangorestframework/mixins.py index 6c8f8179d..8977ccb68 100644 --- a/djangorestframework/mixins.py +++ b/djangorestframework/mixins.py @@ -3,6 +3,7 @@ The :mod:`mixins` module provides a set of reusable `mixin` classes that can be added to a `View`. """ +from collections import Callable from django.contrib.auth.models import AnonymousUser from django.core.paginator import Paginator from django.db.models.fields.related import ForeignKey @@ -513,6 +514,8 @@ class ModelMixin(object): """ Return the queryset for this view. """ + queryset = getattr(self.resource, 'queryset', + self.resource.model.objects.all()) return getattr(self.resource, 'queryset', self.resource.model.objects.all())