Search code examples
jquerypythondjangosearch-engine

sort search result but keep the result - django


I am stuck in this issue:

I have a search engine in my page. one can search and get results of more than 2 pages. I am rendering the pages with paginator. But the current problem is that once I search and sort the result, the search result will be distroyed. After sort, i am getting different search results.

the architecture is this:

normal search:

page/found-items/?state=bla&place=bla

sort on page/found-items/?state=bla&place=bla runs with Jquery.load() function to url: /sort/?sortid=bla.

in my views.py i have two functions:

def search(result):
  #search in db

def sort(request):
  #sort the search result, but how to keep the result after sort??? 

the code is too long, thats why i just posted the form of functions and urls..

appeciate any help


Solution

  • Python lists have a built-in sort() method that modifies the list in-place, but there is also a sorted() built-in function that builds a new sorted list from an iterable.