title: Django search returning Exception Value: object of type 'method' has no len()
body: <p>Pretty new to Django Rest Framework and I'm not quite sure how to debug this error at the moment. When I set a breakpoint in the view search view. I see all my <code>products</code> in <code>results</code></p>
  <pre><code>&lt;bound method QuerySet.distinct of &lt;ProductQuerySet [&lt;Product: Product object (4)&gt;, &lt;Product: Product object (8)&gt;, &lt;Product: Product object (9)&gt;, &lt;Product: Product object (10)&gt;]&gt;&gt;
  </code></pre>
  <p>Pagination is set in settings.py</p>
  <pre><code>REST_FRAMEWORK = {
      &quot;DEFAULT_AUTHENTICATION_CLASSES&quot;: [
          &quot;rest_framework.authentication.SessionAuthentication&quot;,
          &quot;api.authentication.TokenAuthentication&quot;,
      ],
      &quot;DEFAULT_PERMISSION_CLASSES&quot;: [
          &quot;rest_framework.permissions.IsAuthenticatedOrReadOnly&quot;,  # GET for everyone, all other calls need to be authenticated
      ],
      &quot;DEFAULT_PAGINATION_CLASS&quot;: &quot;rest_framework.pagination.LimitOffsetPagination&quot;,
      &quot;PAGE_SIZE&quot;: 10,
  }
  </code></pre>
  <p>Search view</p>
  <pre><code>from rest_framework import generics
  
  from products.models import Product
  from products.serializers import ProductSerializer
  
  
  class SearchListView(generics.ListAPIView):
      queryset = Product.objects.all()
      serializer_class = ProductSerializer
  
      def get_queryset(self, *args, **kwargs):
          qs = super().get_queryset(*args, **kwargs)
          q = self.request.GET.get(&quot;q&quot;)
          results = Product.objects.none()
          if q is not None:
              user = None
              if self.request.user.is_authenticated:
                  user = self.request.user
              results = qs.search(q, user=user)
          return results
  </code></pre>
  <p>Products view</p>
  <pre><code>from rest_framework import generics, mixins
  from django.shortcuts import get_object_or_404
  
  from api.mixins import StaffEditorPermissionMixin, UserQuerySetMixin
  
  from .models import Product
  from .serializers import ProductSerializer
  
  class ProductListCreateAPIView(
      UserQuerySetMixin, StaffEditorPermissionMixin, generics.ListCreateAPIView
  ):
      queryset = Product.objects.all()
      serializer_class = ProductSerializer
  
      def perform_create(self, serializer):
          title = serializer.validated_data.get(&quot;title&quot;)
          content = serializer.validated_data.get(&quot;content&quot;) or None
          if content is None:
              content = title
          serializer.save(user=self.request.user, content=content)
  
  class ProductDetailAPIView(
      UserQuerySetMixin, StaffEditorPermissionMixin, generics.RetrieveAPIView
  ):
      queryset = Product.objects.all()
      serializer_class = ProductSerializer
  </code></pre>
  <p>Products model</p>
  <pre><code>from django.db import models
  from django.conf import settings
  from django.db.models import Q
  
  User = settings.AUTH_USER_MODEL  # auth.User
  
  
  class ProductQuerySet(models.QuerySet):
      def is_public(self):
          return self.filter(public=True)
  
      def search(self, query, user=None):
          lookup = Q(title__icontains=query) | Q(content__icontains=query)
          qs = self.is_public().filter(lookup)
          if user is not None:
              qs2 = self.filter(user=user).filter(lookup)
              qs = (qs | qs2).distinct
          return qs
  
  
  class ProductManager(models.Manager):
      def get_queryset(self, *args, **kwargs):
          return ProductQuerySet(self.model, using=self._db)
  
      def search(self, query, user=None):
          return self.get_queryset().search(query, user=user)
  
  
  class Product(models.Model):
      user = models.ForeignKey(User, default=1, null=True, on_delete=models.SET_NULL)
      title = models.CharField(max_length=120)
      content = models.TextField(blank=True, null=True)
      price = models.DecimalField(max_digits=15, decimal_places=2, default=99.99)
      public = models.BooleanField(default=True)
  
      objects = ProductManager()
  
      @property
      def sale_price(self):
          return &quot;%.2f&quot; % (float(self.price) * 0.8)
  
      # instance method
      def get_discount(self):
          return &quot;122&quot;
  </code></pre>
  <p>Below is the full trace of my error</p>
  <pre><code>Environment:
  
  
  Request Method: GET
  Request URL: http://localhost:8000/api/search/?q=he
  
  Django Version: 4.0.5
  Python Version: 3.10.5
  Installed Applications:
  ['django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',
   'rest_framework',
   'rest_framework.authtoken',
   'api',
   'products',
   'search']
  Installed Middleware:
  ['django.middleware.security.SecurityMiddleware',
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.middleware.common.CommonMiddleware',
   'django.middleware.csrf.CsrfViewMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
   'django.contrib.messages.middleware.MessageMiddleware',
   'django.middleware.clickjacking.XFrameOptionsMiddleware']
  
  
  
  Traceback (most recent call last):
    File &quot;/Users/bradli/Development/learning/drf/venv/lib/python3.10/site-packages/rest_framework/pagination.py&quot;, line 525, in get_count
      return queryset.count()
  
  During handling of the above exception ('function' object has no attribute 'count'), another exception occurred:
    File &quot;/Users/bradli/Development/learning/drf/venv/lib/python3.10/site-packages/django/core/handlers/exception.py&quot;, line 55, in inner
      response = get_response(request)
    File &quot;/Users/bradli/Development/learning/drf/venv/lib/python3.10/site-packages/django/core/handlers/base.py&quot;, line 197, in _get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File &quot;/Users/bradli/Development/learning/drf/venv/lib/python3.10/site-packages/django/views/decorators/csrf.py&quot;, line 54, in wrapped_view
      return view_func(*args, **kwargs)
    File &quot;/Users/bradli/Development/learning/drf/venv/lib/python3.10/site-packages/django/views/generic/base.py&quot;, line 84, in view
      return self.dispatch(request, *args, **kwargs)
    File &quot;/Users/bradli/Development/learning/drf/venv/lib/python3.10/site-packages/rest_framework/views.py&quot;, line 509, in dispatch
      response = self.handle_exception(exc)
    File &quot;/Users/bradli/Development/learning/drf/venv/lib/python3.10/site-packages/rest_framework/views.py&quot;, line 469, in handle_exception
      self.raise_uncaught_exception(exc)
    File &quot;/Users/bradli/Development/learning/drf/venv/lib/python3.10/site-packages/rest_framework/views.py&quot;, line 480, in raise_uncaught_exception
      raise exc
    File &quot;/Users/bradli/Development/learning/drf/venv/lib/python3.10/site-packages/rest_framework/views.py&quot;, line 506, in dispatch
      response = handler(request, *args, **kwargs)
    File &quot;/Users/bradli/Development/learning/drf/venv/lib/python3.10/site-packages/rest_framework/generics.py&quot;, line 199, in get
      return self.list(request, *args, **kwargs)
    File &quot;/Users/bradli/Development/learning/drf/venv/lib/python3.10/site-packages/rest_framework/mixins.py&quot;, line 40, in list
      page = self.paginate_queryset(queryset)
    File &quot;/Users/bradli/Development/learning/drf/venv/lib/python3.10/site-packages/rest_framework/generics.py&quot;, line 171, in paginate_queryset
      return self.paginator.paginate_queryset(queryset, self.request, view=self)
    File &quot;/Users/bradli/Development/learning/drf/venv/lib/python3.10/site-packages/rest_framework/pagination.py&quot;, line 387, in paginate_queryset
      self.count = self.get_count(queryset)
    File &quot;/Users/bradli/Development/learning/drf/venv/lib/python3.10/site-packages/rest_framework/pagination.py&quot;, line 527, in get_count
      return len(queryset)
  
  Exception Type: TypeError at /api/search/
  Exception Value: object of type 'method' has no len()
  </code></pre>