QDjango
|
The QDjango object relational mapper (ORM) supports the concept of querysets, borrowed from django's ORM.
A queryset is a collection of database objects which match a certain number of user-specified conditions.
You can learn more about querysets by reading the QDjangoQuerySet template class documentation.
Before you can start using querysets, you need to declare your database models as described in Database models.
The most basic queryset matches all the objects for a given model.
You can use the QDjangoQuerySet::filter() and QDjangoQuerySet::exclude() methods to add filtering conditions to a querset:
You can also use the QDjangoQuerySet::limit() method to limit the number of returned rows:
The easiest way to iterate over results is to use Qt's foreach keyword:
Another way of iterating over results is to run over model instances using the QDjangoQuerySet::size() and QDjangoQuerySet::at() methods:
It is also possible to retrieve field data without creating model instances using the QDjangoQuerySet::values() and QDjangoQuerySet::valuesList() methods: