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?

Stephen
  • 5,959
  • 10
  • 33
  • 43
  • Does this answer your question? [Change value for paginate\_by on the fly](https://stackoverflow.com/questions/57487336/change-value-for-paginate-by-on-the-fly) – Fumble Feb 17 '23 at 20:58

1 Answers1

3

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:

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_tags.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.

Community
  • 1
  • 1
Lou Franco
  • 87,846
  • 14
  • 132
  • 192
  • 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 Dec 13 '09 at 12:58