def paginate(self, page_num=<NUM_LIT:1>, page_size=<NUM_LIT:100>):
from .database import Page<EOL>count = self.count()<EOL>pages_total = int(ceil(count / float(page_size)))<EOL>if page_num == -<NUM_LIT:1>:<EOL><INDENT>page_num = pages_total<EOL><DEDENT>elif page_num < <NUM_LIT:1>:<EOL><INDENT>raise ValueError('<STR_LIT>' % page_num)<EOL><DEDENT>offset = (page_num - <NUM_LIT:1>) * page_size<EOL>return Page(<EOL>objects=list(self[offset : offset + page_size]),<EOL>number_of_objects=count,<EOL>pages_total=pages_total,<EOL>number=page_num,<EOL>page_size=page_size<EOL>)<EOL>
Returns a single page of model instances that match the queryset.
Note that `order_by` should be used first, to ensure a correct
partitioning of records into pages.

- `page_num`: the page number (1-based), or -1 to get the last page.
- `page_size`: number of records to return per page.

The result is a namedtuple containing `objects` (list), `number_of_objects`,
`pages_total`, `number` (of the current page), and `page_size`.