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
I recently had to do the exact same thing for my site Wantbox.com and found a very simple and effective solution.
I add this snippet in my app's "templatetags" directory in a file called "paginator.py":
Then I add this to the page where I want the pagination:
Changing the "3" to "2" or "4" modifies how the pagination truncates. You can see an example on my site here (top right of the page).
If you are using ListView, here is your paginator function:
My Template
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/
I just implemented this using the "Digg-like Paginator" from Django Snippets.
This is definitely what you are looking for.
Just dump that code into a Python module like
digg_paginator.py
and import it like so...Then in my templates I had to switch from...
to
That's it! The
DiggPaginator
has the exact same interface as Django's built in one plus some features so you can just drop it into place and then adjust it with some customizations if you feel the need.