from rest_framework.pagination import LimitOffsetPagination, CursorPagination
from rest_framework.response import Response
from rest_framework.compat import OrderedDict


class SimpleLimitOffsetPagination(LimitOffsetPagination):
    sort_query_param = 'sort'
    order_query_param = 'order'

    def paginate_queryset(self, queryset, request, view=None):
        sort_attr = request.query_params.get(self.sort_query_param, None)
        if sort_attr is not None:
            order = request.query_params.get(self.order_query_param, None)
            if order == 'desc':
                queryset = queryset.order_by('-' + sort_attr)
            elif order == 'asc':
                queryset = queryset.order_by(sort_attr)
            else:
                # todo warning
                pass

        return super().paginate_queryset(queryset, request, view)

    def get_paginated_response(self, data):
        return Response(OrderedDict([
            ('total', self.count),
            ('rows', data)
        ]))

@@ -162,16 +162,58 @@
 redDict%0A
+from django.db.models import Q, CharField%0A
 %0A%0Aclass 
@@ -325,16 +325,50 @@
  'order'
+%0A    search_query_param = 'search'
 %0A%0A    de
@@ -424,16 +424,433 @@
 =None):%0A
+        search_term = request.query_params.get(self.search_query_param, None)%0A        if search_term is not None:%0A            fields = %5Bf for f in queryset.model._meta.fields if isinstance(f, CharField)%5D%0A            queries = %5BQ(**%7Bf.name + '__contains': search_term%7D) for f in fields%5D%0A            qs = Q()%0A            for query in queries:%0A                qs = qs %7C query%0A            queryset = queryset.filter(qs)%0A%0A
         

add search document by name or description on server side