Thomas Kremmel
Thomas Kremmel

Reputation: 14783

django - the best way to combine pagination with filtering and request.POST - like stackoverflow - ajax?

I want to combine pagination with filtering. Since I have a lot of filters I do not want to send them per GET request, since the URLs get really ugly.

Since django pagination uses GET request to pass the page parameters, I do not know how I can combine these two approaches.

Any idea?

Great add-on would be: How can I combine this approach with table sort? :-)

Edit:

Actually it should work like the pagination of stackoverflow - user questions. If a user clicks on a page number one is shown the correct page, without showing the get parameters in the url.

This is the url called. https://stackoverflow.com/api/userquestions.html?page=2&pagesize=10&userId=237690&sort=Recent

But the url shown in the browser is neat and short. Seems to be ajax. Anybody an idea how to implement this? :)

If the URL is not shown in the browser`s address bar, I do not care about whether it is beautiful or not.

Edit: The solution:

Make an ajax update with all filter parameters passed to the view. This should help you get started with implementing ajax for your site: link

Thus the GET parameters never show up in the address bar.

Upvotes: 7

Views: 5586

Answers (4)

Wilfred Hughes
Wilfred Hughes

Reputation: 31161

Have you considered django-tables2? It gives you django-admin style tables without you having to write the logic yourself.

Upvotes: 2

Sergio
Sergio

Reputation: 1

I figured out two solutions:

  1. Instead of using just hyperlinks use it inside a POST form, i dont have any example now but i remember have used that for REST functions in Ruby on rails
  2. Save the query info in a session.

Hope this help.

Upvotes: 0

PirosB3
PirosB3

Reputation: 2151

have you checked the paginate application for django? it may help you a lot, use it all the time :D

http://code.google.com/p/django-pagination/

Upvotes: 5

diegueus9
diegueus9

Reputation: 31532

maybe you can use the urs, something like:

http://oursite.com/something/filter1/filter2/3/

the doc -> http://docs.djangoproject.com/en/1.1/topics/http/urls/

Upvotes: 0

Related Questions