diff options
| author | Tom Christie | 2014-08-19 10:11:10 +0100 | 
|---|---|---|
| committer | Tom Christie | 2014-08-19 10:11:10 +0100 | 
| commit | e385a7b8eb6e538698f28128e43fe8bfaefd4e97 (patch) | |
| tree | 3f1cac50c40ec77a0bc5537f1a04628901a4d2ce /rest_framework/generics.py | |
| parent | 2aad8e4b35c3552a065347d7eccad8bd51938783 (diff) | |
| parent | 48b66ec2a2b744f170034adbdaaa1588e6c14e11 (diff) | |
| download | django-rest-framework-e385a7b8eb6e538698f28128e43fe8bfaefd4e97.tar.bz2 | |
Merge master
Diffstat (limited to 'rest_framework/generics.py')
| -rw-r--r-- | rest_framework/generics.py | 17 | 
1 files changed, 16 insertions, 1 deletions
| diff --git a/rest_framework/generics.py b/rest_framework/generics.py index e38c52b1..cecb548f 100644 --- a/rest_framework/generics.py +++ b/rest_framework/generics.py @@ -43,6 +43,10 @@ class GenericAPIView(views.APIView):      # You'll need to either set these attributes,      # or override `get_queryset()`/`get_serializer_class()`. +    # If you are overriding a view method, it is important that you call +    # `get_queryset()` instead of accessing the `queryset` property directly, +    # as `queryset` will get evaluated only once, and those results are cached +    # for all subsequent requests.      queryset = None      serializer_class = None @@ -185,7 +189,13 @@ class GenericAPIView(views.APIView):          """          Returns the list of filter backends that this view requires.          """ -        filter_backends = self.filter_backends or [] +        if self.filter_backends is None: +            filter_backends = [] +        else: +            # Note that we are returning a *copy* of the class attribute, +            # so that it is safe for the view to mutate it if needed. +            filter_backends = list(self.filter_backends) +          if not filter_backends and self.filter_backend:              warnings.warn(                  'The `filter_backend` attribute and `FILTER_BACKEND` setting ' @@ -195,6 +205,7 @@ class GenericAPIView(views.APIView):                  DeprecationWarning, stacklevel=2              )              filter_backends = [self.filter_backend] +          return filter_backends @@ -258,6 +269,10 @@ class GenericAPIView(views.APIView):          This must be an iterable, and may be a queryset.          Defaults to using `self.queryset`. +        This method should always be used rather than accessing `self.queryset` +        directly, as `self.queryset` gets evaluated only once, and those results +        are cached for all subsequent requests. +          You may want to override this if you need to provide different          querysets depending on the incoming request. | 
