views:

105

answers:

1

I've implemented django-pagination in my app to take care of pagination, and it's all good. The one thing I can't figure out is how to allow users to choose a certain value for the records per page e.g. 15, 30, 45, 60, 100 or all records.

What's the correct way to go about this?

+2  A: 

When you construct a Paginator, you pass in the number of records per page. You need to get this value from the user, store it, and pass it in.

For example, it could be a user setting -- if so, add it to your user setting Model, collect it in a form, store it, then get the Model from the db before creating the Paginator and pass it in.

Or it could just be a session variable that is set from an element on the page -- again, put the element on the page, use it to set the session variable, and pass it into the Paginator object.

Looks like it was covered in this question:

http://stackoverflow.com/questions/1729332/flexible-pagination-in-django

EDIT: Reading the comment.

If you read the source,

http://code.google.com/p/django-pagination/source/browse/trunk/pagination/templatetags/pagination%5Ftags.py

The tag, autopaginate takes a number or a template variable.

    if isinstance(paginate_by, int):
        self.paginate_by = paginate_by
    else:
        self.paginate_by = template.Variable(paginate_by)

So, try passing in a template variable in your view 'page_by':10 and the use {% autopaginate list page_by %} -- then you can set the page_by from the query string, db, or whatever you want.

Lou Franco
I'd already had a look at that question...correct me if I'm wrong but this approach is for the standard Django paginator. I'm using the django-pagination (http://code.google.com/p/django-pagination/) app
Stephen
thanks Lou....should have known twas this simple :)
Stephen