djangodocs.org

743 sections in Django 6.0 Search all versions →

bulk_update()

Reference QuerySet API reference QuerySet APIMethods that do not return QuerySets

… updates the given fields on the provided model instances, generally with one query, and returns the number of objects updated: QuerySet.update() is used to save the changes, so this is more efficient than iterating through the list of models and …

count()

Reference QuerySet API reference QuerySet APIMethods that do not return QuerySets

count() acount() Asynchronous version: acount() Returns an integer representing the number of objects in the database matching the QuerySet.

in_bulk()

Reference QuerySet API reference QuerySet APIMethods that do not return QuerySets

If id_list isn’t provided, all objects in the queryset are returned. field_name must be a unique field or a distinct field (if there’s only one field specified in distinct()). field_name defaults to the primary key.

iterator()

Reference QuerySet API reference QuerySet APIMethods that do not return QuerySets

iterator(chunk_size=None) aiterator(chunk_size=None) Asynchronous version: aiterator() Evaluates the QuerySet (by performing the query) and returns an iterator (see PEP 234) over the results, or an asynchronous iterator (see PEP 492) if you call its asynchronous version aiterator.

Reference QuerySet API reference QuerySet APIMethods that do not return QuerySetsiterator()

See Isolation when using QuerySet.iterator() for more information. The chunk_size parameter controls the size of batches Django retrieves from the database driver.

latest()

Reference QuerySet API reference QuerySet APIMethods that do not return QuerySets

latest(*fields) alatest(*fields) Asynchronous version: alatest() Returns the latest object in the table based on the given field(s).

earliest()

Reference QuerySet API reference QuerySet APIMethods that do not return QuerySets

earliest(*fields) aearliest(*fields) Asynchronous version: aearliest() Works otherwise like latest() except the direction is changed.

first()

Reference QuerySet API reference QuerySet APIMethods that do not return QuerySets

first() afirst() Asynchronous version: afirst() Returns the first object matched by the queryset, or None if there is no matching object. If the QuerySet has no ordering defined, then the queryset is automatically ordered by the primary key.

last()

Reference QuerySet API reference QuerySet APIMethods that do not return QuerySets

last() alast() Asynchronous version: alast() Works like first(), but returns the last object in the queryset.

aggregate()

Reference QuerySet API reference QuerySet APIMethods that do not return QuerySets

aggregate(*args,**kwargs) aaggregate(*args,**kwargs) Asynchronous version: aaggregate() Returns a dictionary of aggregate values (averages, sums, etc.) calculated over the QuerySet. Each argument to aggregate() specifies a value that will be included in the dictionary that is returned.

exists()

Reference QuerySet API reference QuerySet APIMethods that do not return QuerySets

exists() aexists() Asynchronous version: aexists() Returns True if the QuerySet contains any results, and False if not.

contains()

Reference QuerySet API reference QuerySet APIMethods that do not return QuerySets

contains(obj) acontains(obj) Asynchronous version: acontains() Returns True if the QuerySet contains obj, and False if not. This tries to perform the query in the simplest and fastest way possible.

update()

Reference QuerySet API reference QuerySet APIMethods that do not return QuerySets

… here we update the comments_on and headline fields: The update() method is applied instantly, and the only restriction on the QuerySet that is updated is that it can only update columns in the model’s main table, not on related models. …

delete()

Reference QuerySet API reference QuerySet APIMethods that do not return QuerySets

delete() adelete() Asynchronous version: adelete() Performs an SQL delete query on all rows in the QuerySet and returns the number of objects deleted and a dictionary with the number of deletions per object type. The delete() is applied instantly.

as_manager()

Reference QuerySet API reference QuerySet APIMethods that do not return QuerySets

classmethodas_manager() Class method that returns an instance of Manager with a copy of the QuerySet’s methods. See Creating a manager with QuerySet methods for more details.

explain()

Reference QuerySet API reference QuerySet APIMethods that do not return QuerySets

explain(format=None,**options) aexplain(format=None,**options) Asynchronous version: aexplain() Returns a string of the QuerySet’s execution plan, which details how the database would execute the query, including any indexes or joins that would be used.

Field lookups

Reference QuerySet API reference QuerySet API

They’re specified as keyword arguments to the QuerySet methods filter(), exclude() and get(). For an introduction, see models and database queries documentation. Django’s built-in lookups are listed below. It is also possible to write custom lookups for model fields.

in

Reference QuerySet API reference QuerySet APIField lookups

In a given iterable; often a list, tuple, or queryset. It’s not a common use case, but strings (being iterables) are accepted.

Aggregation functions

Reference QuerySet API reference QuerySet API

Attempts to use > aggregation on date/time fields in SQLite will raise NotSupportedError. NOTE: Aggregation functions return None when used with an empty QuerySet > or group.

default

Reference QuerySet API reference QuerySet APIAggregation functions

An optional argument that allows specifying a value to use as a default value when the queryset (or grouping) contains no entries.