code: def paginate(self, model_class, order_by, page_num=1, page_size=100, conditions=None, settings=None):
          '''
          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`.
          '''
          count = self.count(model_class, conditions)
          pages_total = int(ceil(count / float(page_size)))
          if page_num == -1:
              page_num = max(pages_total, 1)
          elif page_num < 1:
              raise ValueError('Invalid page number: %d' % page_num)
          offset = (page_num - 1) * page_size
          query = 'SELECT * FROM $table'
          if conditions:
              query += ' WHERE ' + conditions
          query += ' ORDER BY %s' % order_by
          query += ' LIMIT %d, %d' % (offset, page_size)
          query = self._substitute(query, model_class)
          return Page(
              objects=list(self.select(query, model_class, settings)) if count else [],
              number_of_objects=count,
              pages_total=pages_total,
              number=page_num,
              page_size=page_size
          )