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.
766 sections in Django dev Search all versions →
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.
Reference QuerySet API reference QuerySet APIAggregation functions
classAnyValue(expression,output_field=None,filter=None,default=None,**extra)[source] : Returns an arbitrary value from the non-null input values.
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.
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.
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.
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.
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.
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.
Reference QuerySet API reference QuerySet APIAggregation functions
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.
Reference QuerySet API reference Query-related tools
classPrefetch(lookup,queryset=None,to_attr=None)[source] The Prefetch() object can be used to control the operation of prefetch_related(). The lookup argument describes the relations to follow and works the same as the string based lookups passed to prefetch_related().
Reference QuerySet API reference Query-related tools
This is useful in code that receives a list of model instances as opposed to a QuerySet; for example, when fetching models from a cache or instantiating them manually.
Reference QuerySet API reference Query-related tools
… find restaurants that have vegetarian pizzas with 'mozzarella' in the name: If there are a large number of pizzas, this queryset performs better than: because the filtering in the WHERE clause of the first queryset will only operate on vegetarian …
Reference GIS QuerySet API Reference Distance LookupsAggregate Functions
classExtent(geo_field,filter=None)[source] Availability: PostGIS, Oracle, SpatiaLite Returns the extent of all geo_field in the QuerySet as a 4-tuple, comprising the lower left coordinate and the upper right coordinate. Example:
Reference GIS QuerySet API Reference Distance LookupsAggregate Functions
classExtent3D(geo_field,filter=None)[source] Availability: PostGIS Returns the 3D extent of all geo_field in the QuerySet as a 6-tuple, comprising the lower left coordinate and upper right coordinate (each with x, y, and z coordinates). Example:
Reference GIS QuerySet API Reference Distance LookupsAggregate Functions
classMakeLine(geo_field,filter=None)[source] Availability: PostGIS, SpatiaLite Returns a LineString constructed from the point field geometries in the QuerySet. Currently, ordering the queryset has no effect. Example:
Reference GIS QuerySet API Reference Distance LookupsAggregate Functions
classUnion(geo_field,filter=None)[source] Availability: PostGIS, Oracle, SpatiaLite This method returns a GEOSGeometry object comprising the union of every geometry in the queryset. Please note that use of Union is processor intensive and may take a significant amount of time on large querysets.
Reference The Django admin site ModelAdmin objects
ModelAdmin.get_queryset(request) : The get_queryset method on a ModelAdmin returns a QuerySet of all model instances that can be edited by the admin site.
Reference PostgreSQL specific query expressions
classArraySubquery(queryset)[source] ArraySubquery is a Subquery that uses the PostgreSQL ARRAY constructor to build a list of values from the queryset, which must use QuerySet.values() to return only a single column.
Reference Query Expressions Built-in Expressions
classSubquery(queryset,output_field=None)[source] You can add an explicit subquery to a QuerySet using the Subquery expression.
Reference Query Expressions Built-in ExpressionsSubquery() expressions
classExists(queryset)[source] Exists is a Subquery subclass that uses an SQL EXISTS statement. In many cases it will perform better than a subquery since the database is able to stop evaluation of the subquery when a first matching row is found.