def paginate(self, model_class, order_by, page_num=<NUM_LIT:1>, page_size=<NUM_LIT:100>, conditions=None, settings=None):
count = self.count(model_class, conditions)<EOL>pages_total = int(ceil(count / float(page_size)))<EOL>if page_num == -<NUM_LIT:1>:<EOL><INDENT>page_num = max(pages_total, <NUM_LIT:1>)<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>query = '<STR_LIT>'<EOL>if conditions:<EOL><INDENT>query += '<STR_LIT>' + conditions<EOL><DEDENT>query += '<STR_LIT>' % order_by<EOL>query += '<STR_LIT>' % (offset, page_size)<EOL>query = self._substitute(query, model_class)<EOL>return Page(<EOL>objects=list(self.select(query, model_class, settings)) if count else [],<EOL>number_of_objects=count,<EOL>pages_total=pages_total,<EOL>number=page_num,<EOL>page_size=page_size<EOL>)<EOL>
Selects records and returns a single page of model instances.

- `model_class`: the model class matching the query's table,
  or `None` for getting back instances of an ad-hoc model.
- `order_by`: columns to use for sorting the query (contents of the ORDER BY clause).
- `page_num`: the page number (1-based), or -1 to get the last page.
- `page_size`: number of records to return per page.
- `conditions`: optional SQL conditions (contents of the WHERE clause).
- `settings`: query settings to send as HTTP GET parameters

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