Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'll need to do something moderately more complex behind the scenes. And please note that while I am a python dev, i've been using werkzeug and jinja2 for a long time now and so my django syntax is a little rusty. Also this was dry-coded (as in I just typed it here in the browser) and should be tested to make sure that it works as intended.</p> <p>Generally I'll create a pagination object, and pass it in a query object that isn't filtered by pages, you can also tell it how many per page and what page you're on.</p> <p>So something vaguely similar to:</p> <pre><code>Paginator(query, objects_per_page, current_page_number) </code></pre> <p>And then pass the resulting paginator object into the template.</p> <p>Inside the paginator's <strong>init</strong> you'd want to do something similar to:</p> <pre><code>def __init__(self, query, objects_per_page, current_page_number): self.total = query.count() self.per_page = objects_per_page self.current_page_number = current_page_number self.lower_limit = objects_per_page * current_page_number self.upper_limit = objects_per_page * (current_page_number + 1) if self.upper_limit &gt; self.total: self.upper_limit = self.total self.objects = query[self.lower_limit - 1:self.upper_limit - 1] </code></pre> <p>Then in the template you'd do something like</p> <pre><code>Showing {{paginator.lower_limit}}-{{paginator.upper_limit}} of {{paginator.total}} </code></pre> <p>And later when you are ready to iterate over the objects you could just iterate over paginator.objects.</p> <p>I hope that gives you a general idea of how you can cleanly do this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload