Utilities — flask-peewee v0.1.0 documentation

### Navigation

- index
- previous |
- flask-peewee v0.1.0 documentation »

# Utilities

flask-peewee ships with several useful utilities. If you’re coming from the django world, some of these functions may look familiar to you.

`get_object_or_404`(query_or_model, **query)

  Given any number of keyword arguments, retrieve a single instance of the `query_or_model` parameter or return a 404

  Parameters: | query_or_model – either a `Model` class or a `SelectQuery` **query – any number of keyword arguments, e.g. `id=1`
  Return type: | either a single model instance or raises a `NotFound` (404 response)

`object_list`(template_name, qr[, var_name='object_list'[, **kwargs]])

  Returns a rendered template, passing in a paginated version of the query.

  Parameters: | template_name – a string representation of a path to a template qr – a `SelectQuery` var_name – context variable name to use when rendering the template **kwargs – any arbitrary keyword arguments to pass to the template during rendering
  Return type: | rendered `Response`

`get_next`()

  Return type: | a URL suitable for redirecting to

`slugify`(s)

  Use a regular expression to make arbitrary string `s` URL-friendly

  Parameters: | s – any string to be slugified
  Return type: | url-friendly version of string `s`

class `PaginatedQuery`

  Wraps a `SelectQuery` with helpers for paginating.

  `page_var = 'page'`

    GET argument to use for determining request page

  `__init__`(query_or_model, paginate_by)

    Parameters: | query_or_model – either a `Model` class or a `SelectQuery` paginate_by – number of results to return per-page

  `get_list`()

    Return type: | a list of objects for the request page

  `get_page`()

    Return type: | an integer representing the currently requested page

  `get_pages`()

    Return type: | the number of pages in the entire result set

### Navigation

- index
- previous |
- flask-peewee v0.1.0 documentation »