diff options
| author | Jens Alm | 2012-10-15 11:47:56 +0200 | 
|---|---|---|
| committer | Jens Alm | 2012-10-15 11:47:56 +0200 | 
| commit | de4604be0ab64da2d7da0a7054197278e566ced2 (patch) | |
| tree | edc26439c281c985efabb2a95344da87f3fd3c75 /rest_framework | |
| parent | 36cc56bc9d49832ca990ba8568903966f46a2938 (diff) | |
| download | django-rest-framework-de4604be0ab64da2d7da0a7054197278e566ced2.tar.bz2 | |
Support for request-based queryset limits on ListModelMixin
ListModelMixin uses the get_queryset from the MultipleObjectMixin. This
method can be overridden on the View class to return a different
queryset, but get_queryset doesn't accept a request parameter in. This
commit adds the limit_list hook to override if you want to limit the
queryset based on request-information such as the logged in user.
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/mixins.py | 9 | 
1 files changed, 8 insertions, 1 deletions
diff --git a/rest_framework/mixins.py b/rest_framework/mixins.py index 29153e18..2834c882 100644 --- a/rest_framework/mixins.py +++ b/rest_framework/mixins.py @@ -32,8 +32,15 @@ class ListModelMixin(object):      """      empty_error = u"Empty list and '%(class_name)s.allow_empty' is False." +    def limit_list(self, request, queryset): +        """ +        Override this method to limit the queryset based on information in the request, such as the logged in user. +        Should return the limited queryset, defaults to no limits. +        """ +        return queryset +      def list(self, request, *args, **kwargs): -        self.object_list = self.get_queryset() +        self.object_list = self.limit_list(request, self.get_queryset())          # Default is to allow empty querysets.  This can be altered by setting          # `.allow_empty = False`, to raise 404 errors on empty querysets.  | 
