Django pagination...slicing pages to show fraction of total pages?

Ben picture Ben · Mar 24, 2011 · Viewed 13.3k times · Source

I have the pagination module working for the most part but there's one issue. How can I only show a slice of the total available pages. For example, let's say I'm on page 5 of n pages, I'd want to show.

1,2,3,4,5,6....(n-1)(n).

I believe that Ruby has some fancy front-end magic to accomplish this. Is there anything that I can do within the django module?

From looking at other sites, it seems as though the logic basically goes, pick a fixed number of spots. If that number is larger than the amount currently display, add items when users page forward. Once that number of spots is reached, only show x spots to the left and right of the current page.

Should I just write my own template logic to accomplish that?

Thanks

Answer

dting picture dting · Mar 25, 2011

Quite a few nice articles about implementing what you are asking for in django. Lots of pluggable packages to customize if you don't want to roll your own.

http://www.tummy.com/Community/Articles/django-pagination/

https://github.com/dcramer/django-paging

Very well document snippet that wraps the built in paginator:

http://blog.elsdoerfer.name/2008/03/06/yet-another-paginator-digg-style/