aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework
diff options
context:
space:
mode:
authorChris Pickett2012-01-19 12:56:09 -0500
committerChris Pickett2012-01-19 12:56:09 -0500
commit338e77837c9df6f36c77db67a65a3a485b1064a4 (patch)
treeb892cc80b81f02ed6279a1db30d4869f2d48a944 /djangorestframework
parent0a5ca000edcd8fba1e5e5f71c7267d9f52e456a0 (diff)
downloaddjango-rest-framework-338e77837c9df6f36c77db67a65a3a485b1064a4.tar.bz2
Added get_queryset method to ListModelMixin.
This can be easily re-implemented in a view, to allow the user to take such things as request.user into account when creating the queryset.
Diffstat (limited to 'djangorestframework')
-rw-r--r--djangorestframework/mixins.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/djangorestframework/mixins.py b/djangorestframework/mixins.py
index 15d7faf0..c7f7b10c 100644
--- a/djangorestframework/mixins.py
+++ b/djangorestframework/mixins.py
@@ -675,9 +675,7 @@ class ListModelMixin(ModelMixin):
queryset = None
def get(self, request, *args, **kwargs):
- model = self.resource.model
-
- queryset = self.queryset if self.queryset is not None else model.objects.all()
+ queryset = self.get_queryset()
if hasattr(self, 'resource'):
ordering = getattr(self.resource, 'ordering', None)
@@ -689,6 +687,10 @@ class ListModelMixin(ModelMixin):
queryset = queryset.order_by(*args)
return queryset.filter(self.build_query(**kwargs))
+ def get_queryset(self):
+ model = self.resource.model
+ return model.objects.all() if self.queryset is None else self.queryset
+
########## Pagination Mixins ##########