djangodocs.org

743 sections across all versions Narrow to Django 6.0 (current) →

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.

AnyValue

Reference QuerySet API reference QuerySet APIAggregation functions

New in Django 6.0. classAnyValue(expression,output_field=None,filter=None,default=None,**extra)[source] : Returns an arbitrary value from the non-null input values.

6.0 dev

Avg

Reference QuerySet API reference QuerySet APIAggregation functions

classAvg(expression,output_field=None,distinct=False,filter=None,default=None,**extra)[source] : Returns the mean value of the given expression, which must be numeric unless you specify a different output_field.

Max

Reference QuerySet API reference QuerySet APIAggregation functions

classMax(expression,output_field=None,filter=None,default=None,**extra)[source] : Returns the maximum value of the given expression.

Min

Reference QuerySet API reference QuerySet APIAggregation functions

classMin(expression,output_field=None,filter=None,default=None,**extra)[source] : Returns the minimum value of the given expression.

StdDev

Reference QuerySet API reference QuerySet APIAggregation functions

classStdDev(expression,output_field=None,sample=False,filter=None,default=None,**extra)[source] : Returns the standard deviation of the data in the provided expression.

Sum

Reference QuerySet API reference QuerySet APIAggregation functions

classSum(expression,output_field=None,distinct=False,filter=None,default=None,**extra)[source] : Computes the sum of all values of the given expression.

Variance

Reference QuerySet API reference QuerySet APIAggregation functions

classVariance(expression,output_field=None,sample=False,filter=None,default=None,**extra)[source] : Returns the variance of the data in the provided expression.

StringAgg

Reference QuerySet API reference QuerySet APIAggregation functions

New in Django 6.0. classStringAgg(expression,delimiter,output_field=None,distinct=False,filter=None,order_by=None,default=None,**extra)[source] : Returns the input values concatenated into a string, separated by the delimiter string, or default if there are no values.

6.0 dev