0

I'm building an application that allows to page the result of a search. The results can be numerous that's why I used django's pagination. I have configured filters and sorting of results displayed by 10: `

def search_details(request, type_anc):
    querylist = Annonce.objects.filter(type_annonce = type_anc, is_published=True)
    ...........
    paginator = Paginator(querylist, 10)
    page = request.GET.get('page')
    paged_listings = paginator.get_page(page)

` When I click on the button that sends me to the next page, 'order_by' is not respected. For example I have a result that sorts the price by descending order and the last element is 850 000, in the next page the prices displayed should be below 850 000. Can you help me?

1 Answers1

0

Actually, this question seems to be unclear but I framed my answer according to the details provided. (Please provide a meaningful problem statement, need modal and template details also to provide a solution...)

Here Your modal name is Announce, you need to paginate by 10 and it's a search function. here I assume your template name to be 'XYZ.html' so views gonna be

views.py

from django.core.paginator import Paginator
from django.shortcuts import render
from .moddels import Announce

def search_details(request, type_anc):
    announce_list = Announce.objects.filter(type_annonce=type_anc, is_published=True)
    paginator = Paginator(announce_list, 10)
    page_number = request.GET.get('page')
    page_obj = paginator.get_page(page_number)
    return render(resuest, 'XYZ.html', {'page_obj': page_obj})

Here page_obj holds the data for the page that which user requests... you can render the data in the template by following the Django docs.Here is the link https://docs.djangoproject.com/en/4.1/topics/pagination/#:~:text=%7B%25%20for%20contact,%3C/div%3E