2015-12-19 14:52:17 +01:00
|
|
|
title: Query
|
|
|
|
---
|
|
|
|
summary: Provides functionality to query the database.
|
|
|
|
---
|
|
|
|
module: lektor.db
|
|
|
|
---
|
|
|
|
type: class
|
|
|
|
---
|
|
|
|
body:
|
|
|
|
|
|
|
|
The query class is used to filter queries to the database. It's available
|
|
|
|
through either the [Pad :ref](../pad/) or through things like the
|
|
|
|
[children :ref](../record/children/) property of records.
|
|
|
|
|
|
|
|
Most operations on a query object return another one which will return a
|
|
|
|
more filtered result.
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
Here a basic example of how to filter something in a template:
|
|
|
|
|
|
|
|
```html+jinja
|
|
|
|
<ul>
|
|
|
|
{% for item in this.children.filter(F.status == 'published') %}
|
2016-07-22 17:47:09 +02:00
|
|
|
<li>{{ item.title }}</li>
|
2015-12-19 14:52:17 +01:00
|
|
|
{% endfor %}
|
|
|
|
</ul>
|
|
|
|
```
|