QDjangoQuerySet< T > Class Template Reference
Database

The QDjangoQuerySet class is a template class for performing database queries. More...

`#include <QDjangoQuerySet.h>`

## Classes

class | const_iterator

## Public Types

typedef const_iterator | ConstIterator

## Public Member Functions

| QDjangoQuerySet ()
| QDjangoQuerySet (const QDjangoQuerySet< T > &other)
| ~QDjangoQuerySet ()
QDjangoQuerySet | all () const
QDjangoQuerySet | exclude (const QDjangoWhere &where) const
QDjangoQuerySet | filter (const QDjangoWhere &where) const
QDjangoQuerySet | limit (int pos, int length=-1) const
QDjangoQuerySet | none () const
QDjangoQuerySet | orderBy (const QStringList &keys) const
QDjangoQuerySet | selectRelated () const
int | count () const
QDjangoWhere | where () const
bool | remove ()
int | size ()
int | update (const QVariantMap &fields)
QList< QVariantMap > | values (const QStringList &fields=QStringList())
QList< QVariantList > | valuesList (const QStringList &fields=QStringList())
T * | get (const QDjangoWhere &where, T *target=0) const
T * | at (int index, T *target=0)
const_iterator | constBegin () const
const_iterator | begin () const
const_iterator | constEnd () const
const_iterator | end () const
QDjangoQuerySet< T > & | operator= (const QDjangoQuerySet< T > &other)

## Detailed Description

### template<class T>
class QDjangoQuerySet< T >

The QDjangoQuerySet class is a template class for performing database queries.

The QDjangoQuerySet template class allows you to define and manipulate sets of QDjangoModel objects stored in the database.

You can chain filter expressions using the filter() and exclude() methods or apply limits on the number of rows using the limit() method.

You can retrieve database values using the values() and valuesList() methods or retrieve model instances using the get() and at() methods.

You can also delete sets of objects using the remove() method.

Behinds the scenes, the QDjangoQuerySet class uses implicit sharing to reduce memory usage and avoid needless copying of data.

## Member Typedef Documentation

## ConstIterator

template<class T >

typedef const_iterator QDjangoQuerySet< T >::ConstIterator

Qt-style synonym for QDjangoQuerySet::const_iterator.

## Constructor & Destructor Documentation

## QDjangoQuerySet() [1/2]

template<class T >

QDjangoQuerySet< T >::QDjangoQuerySet

Constructs a new queryset.

## QDjangoQuerySet() [2/2]

template<class T >

QDjangoQuerySet< T >::QDjangoQuerySet | ( | const QDjangoQuerySet< T > & | other | ) |

Constructs a copy of other.

Parameters

  other |

## ~QDjangoQuerySet()

template<class T >

QDjangoQuerySet< T >::~QDjangoQuerySet

Destroys the queryset.

## Member Function Documentation

## all()

template<class T >

QDjangoQuerySet< T > QDjangoQuerySet< T >::all

Returns a copy of the current QDjangoQuerySet.

## at()

template<class T >

T * QDjangoQuerySet< T >::at | ( | int | index,
|  | T * | target = `0`
| ) |  |

Returns the object in the QDjangoQuerySet at the given index.

Returns 0 if the index is out of bounds.

If target is 0, a new object instance will be allocated which you must free yourself.

Parameters

  index |
  target | optional existing model instance.

## begin()

template<class T >

QDjangoQuerySet< T >::const_iterator QDjangoQuerySet< T >::begin

Returns a const STL-style iterator pointing to the first object in the QDjangoQuerySet.

See also
  constBegin() and end().

## constBegin()

template<class T >

QDjangoQuerySet< T >::const_iterator QDjangoQuerySet< T >::constBegin

Returns a const STL-style iterator pointing to the first object in the QDjangoQuerySet.

See also
  begin() and constEnd().

## constEnd()

template<class T >

QDjangoQuerySet< T >::const_iterator QDjangoQuerySet< T >::constEnd

Returns a const STL-style iterator pointing to the imaginary object after the last object in the QDjangoQuerySet.

See also
  constBegin() and end().

## count()

template<class T >

int QDjangoQuerySet< T >::count

Counts the number of objects in the queryset using an SQL COUNT query, or -1 if the query failed.

If you intend to iterate over the results, you should consider using size() instead.

Note
  If the QDjangoQuerySet is already fully fetched, this simply returns the number of objects.

## end()

template<class T >

QDjangoQuerySet< T >::const_iterator QDjangoQuerySet< T >::end

Returns a const STL-style iterator pointing to the imaginary object after the last object in the QDjangoQuerySet.

See also
  begin() and constEnd().

## exclude()

template<class T >

QDjangoQuerySet< T > QDjangoQuerySet< T >::exclude | ( | const QDjangoWhere & | where | ) | const

Returns a new QDjangoQuerySet containing objects for which the given key where condition is false.

You can chain calls to filter() and exclude() to further refine the filtering conditions.

Parameters

  where | QDjangoWhere expressing the exclude condition

See also
  filter()

## filter()

template<class T >

QDjangoQuerySet< T > QDjangoQuerySet< T >::filter | ( | const QDjangoWhere & | where | ) | const

Returns a new QDjangoQuerySet containing objects for which the given where condition is true.

You can chain calls to filter() and exclude() to progressively refine your filtering conditions.

Parameters

  where | QDjangoWhere expressing the filter condition

See also
  exclude()

## get()

template<class T >

T * QDjangoQuerySet< T >::get | ( | const QDjangoWhere & | where,
|  | T * | target = `0`
| ) |  | const

Returns the object in the QDjangoQuerySet for which the given where condition is true.

Returns 0 if the number of matching object is not exactly one.

If target is 0, a new object instance will be allocated which you must free yourself.

Parameters

  where | QDjangoWhere expressing the lookup condition
  target | optional existing model instance.

## limit()

template<class T >

QDjangoQuerySet< T > QDjangoQuerySet< T >::limit | ( | int | pos,
|  | int | length = `-1`
| ) |  | const

Returns a new QDjangoQuerySet containing limiting the number of records to manipulate.

You can chain calls to limit() to further restrict the number of returned records.

However, you cannot apply additional restrictions using filter(), exclude(), get(), orderBy() or remove() on the returned QDjangoQuerySet.

Parameters

  pos | offset of the records
  length | maximum number of records

## none()

template<class T >

QDjangoQuerySet< T > QDjangoQuerySet< T >::none

Returns an empty QDjangoQuerySet.

## operator=()

template<class T >

QDjangoQuerySet< T > & QDjangoQuerySet< T >::operator= | ( | const QDjangoQuerySet< T > & | other | ) |

Assigns the specified queryset to this object.

Parameters

  other |

## orderBy()

template<class T >

QDjangoQuerySet< T > QDjangoQuerySet< T >::orderBy | ( | const QStringList & | keys | ) | const

Returns a QDjangoQuerySet whose elements are ordered using the given keys.

By default the elements will by in ascending order. You can prefix the key names with a "-" (minus sign) to use descending order.

Parameters

  keys |

## remove()

template<class T >

bool QDjangoQuerySet< T >::remove

Deletes all objects in the QDjangoQuerySet.

Returns
  true if deletion succeeded, false otherwise

## selectRelated()

template<class T >

QDjangoQuerySet< T > QDjangoQuerySet< T >::selectRelated

Returns a QDjangoQuerySet that will automatically "follow" foreign-key relationships, selecting that additional related-object data when it executes its query.

## size()

template<class T >

int QDjangoQuerySet< T >::size

Returns the number of objects in the QDjangoQuerySet, or -1 if the query failed.

If you do not plan to access the objects, you should consider using count() instead.

## update()

template<class T >

int QDjangoQuerySet< T >::update | ( | const QVariantMap & | fields | ) |

Performs an SQL update query for the specified fields and returns the number of rows affected, or -1 if the update failed.

## values()

template<class T >

QList< QVariantMap > QDjangoQuerySet< T >::values | ( | const QStringList & | fields = `QStringList()` | ) |

Returns a list of property hashes for the current QDjangoQuerySet. If no fields are specified, all the model's declared fields are returned.

Parameters

  fields |

## valuesList()

template<class T >

QList< QVariantList > QDjangoQuerySet< T >::valuesList | ( | const QStringList & | fields = `QStringList()` | ) |

Returns a list of property lists for the current QDjangoQuerySet. If no fields are specified, all the model's fields are returned in the order they where declared.

Parameters

  fields |

## where()

template<class T >

QDjangoWhere QDjangoQuerySet< T >::where

Returns the QDjangoWhere expressing the WHERE clause of the QDjangoQuerySet.

The documentation for this class was generated from the following file:

- QDjangoQuerySet.h