0

I know how to use django pagination with ORM django after filtering the required data and put in into pagination div

queryset_list = employee.objects.all()
query=request.GET.get("q")
        if query:
            queryset_list=queryset_list.filter(
              Q(name__icontains=query)|
              Q(father_name__icontains=query)|
              Q(mother_name__icontains=query)|
              Q(content__icontains=query)|
              Q(create_date__icontains=query)
              # Q(user__first_name__contains=query)
            ).distinct()


        paginator = Paginator(queryset_list, 5)
        page_request_var = "page"
        page = request.GET.get(page_request_var)
        queryset = paginator.get_page(page)

        context={
            "object_list":queryset,
            "title":"List Items",
            "page_request_var":page_request_var,
        }
        return render(request,"blog/list.html", context)

The above code is working

My question is how to convert this ORM into raw SQL

I know that I must use LIMIT and OFFSET in raw SQL to embedded into paginator.

Dale K
  • 25,246
  • 15
  • 42
  • 71
Dev Dj
  • 169
  • 2
  • 14
  • `LIMIT` is MySQL you want [`OFFSET` & `FETCH`](http://www.sqlservertutorial.net/sql-server-basics/sql-server-offset-fetch/) – Dale K Sep 25 '19 at 05:39
  • @DaleBurrell okk i did not know that so i will try to search on fetch – Dev Dj Sep 25 '19 at 05:42
  • Try the link I gave you - it has an example :) – Dale K Sep 25 '19 at 05:43
  • ok so it say how to use offset and fetch in sql server but how to use it with django pagination? how to use the result of the query in the django pagination syntax `paginator = Paginator(queryset_list, 5) page_request_var = "page" page = request.GET.get(page_request_var) queryset = paginator.get_page(page)` – Dev Dj Sep 25 '19 at 05:48

0 Answers0