I don't want to run count queries on views where count is not needed. How can I turn it off?
I found the following workaround in another post on stackoverflow. The count query is not fired, but I can see pages that have no data. (I can see up to ?page=10000, even though there are only about 10 pages.)
#settings.py
REST_FRAMEWORK = {
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
"PAGE_SIZE": 20,
...
}
import sys
from django.core.paginator import Paginator
from django.utils.functional import cached_property
from rest_framework.pagination import PageNumberPagination
class CustomPaginatorClass(Paginator):
@cached_property
def count(self):
return sys.maxsize
class CustomPagination(PageNumberPagination):
django_paginator_class = CustomPaginatorClass