Class QuerySet

Class that represents a list of model instances that are retrieved by a database query.

class QuerySet(modelDef, manager)
Arguments:
  • modelDef (Object) – Definition of the model. See Model.
  • manager (ModelManager) – The model manager of the model that is the base for this query set.

See also

Model

Methods

all

Fetches all instances of the model which are in the db. This method actually hits the database and evaluates the query set.

QuerySet.prototype.all(onComplete)
Arguments:
  • onComplete
    {Function}
    Callback that is called with a list of all instances.

clone

Creates a deep copy of this object (except cache).

QuerySet.prototype.clone()

convertLookups

Converts a lookup object into an SQL WHERE condition.

QuerySet.prototype.convertLookups(queryObj, values)
Arguments:
  • queryObj
  • values

delete

Deletes all objects this query set represents.

QuerySet.prototype.delete(onComplete)
Arguments:
  • onComplete – {Function} Callback that is called when deletion is done. No arguments are passed.

exclude

Returns a QuerySet which represents all instances of the model which do NOT validate against queryObj. This QuerySet remains unchanged.

QuerySet.prototype.exclude(queryObj)
Arguments:
  • queryObj
    {Object}
    field lookups or Q object.

filter

Returns a QuerySet which represents all instances of the model which validate against queryObj. This QuerySet remains unchanged.

QuerySet.prototype.filter(queryObj)
Arguments:
  • queryObj
    {Object}
    field lookups or Q object.

get

Fetches the object that machtes the lookup parameters given by queryObj. The format of queryObj is the same as in filter(). If no or more than one result is found, an exception is thrown.

QuerySet.prototype.get(queryObj, onComplete)
Arguments:
  • queryObj
    {Object}
    field lookups or Q object.
  • onComplete
    {Function}
    Callback that is called with the fetched instance.

orderBy

Returns a new QuerySet that is ordered by the given fields.

QuerySet.prototype.orderBy()
Entry.objects.orderBy('-pub_date', 'headline').all(...);