djangodocs.org

705 sections in Django 5.1 Search all versions →

quarter

Reference QuerySet API reference QuerySet APIField lookups

For date and datetime fields, a ‘quarter of the year’ match. Allows chaining additional field lookups. Takes an integer value between 1 and 4 representing the quarter of the year.

time

Reference QuerySet API reference QuerySet APIField lookups

For datetime fields, casts the value as time. Allows chaining additional field lookups. Takes a datetime.time value.

hour

Reference QuerySet API reference QuerySet APIField lookups

For datetime and time fields, an exact hour match. Allows chaining additional field lookups. Takes an integer between 0 and 23.

minute

Reference QuerySet API reference QuerySet APIField lookups

For datetime and time fields, an exact minute match. Allows chaining additional field lookups. Takes an integer between 0 and 59.

second

Reference QuerySet API reference QuerySet APIField lookups

For datetime and time fields, an exact second match. Allows chaining additional field lookups. Takes an integer between 0 and 59.

isnull

Reference QuerySet API reference QuerySet APIField lookups

Takes either True or False, which correspond to SQL queries of IS NULL and IS NOT NULL, respectively. Example: SQL equivalent:

regex

Reference QuerySet API reference QuerySet APIField lookups

Case-sensitive regular expression match. The regular expression syntax is that of the database backend in use.

iregex

Reference QuerySet API reference QuerySet APIField lookups

Case-insensitive regular expression match. Example: SQL equivalents:

expressions

Reference QuerySet API reference QuerySet APIAggregation functions

Strings that reference fields on the model, transforms of the field, or query expressions.

output_field

Reference QuerySet API reference QuerySet APIAggregation functions

An optional argument that represents the model field of the return value NOTE: When combining multiple field types, Django can only determine the > output_field if all fields are of the same type.

filter

Reference QuerySet API reference QuerySet APIAggregation functions

An optional Q object that’s used to filter the rows that are aggregated. See Conditional aggregation and Filtering on annotations for example usage.

**extra

Reference QuerySet API reference QuerySet APIAggregation functions

Keyword arguments that can provide extra context for the SQL generated by the aggregate.

Count

Reference QuerySet API reference QuerySet APIAggregation functions

classCount(expression,distinct=False,filter=None,**extra)[source] : Returns the number of objects that are related through the provided expression. Count('*') is equivalent to the SQL COUNT(*) expression.

Q() objects

Reference QuerySet API reference Query-related tools

classQ[source] A Q() object represents an SQL condition that can be used in database-related operations. It’s similar to how an F() object represents the value of a model field or annotation. They make it possible to define and reuse conditions.

Spatial Lookups

Reference GIS QuerySet API Reference

The spatial lookups in this section are available for GeometryField and RasterField. For an introduction, see the spatial lookups introduction. For an overview of what lookups are compatible with a particular spatial backend, refer to the spatial lookup compatibility table.

Lookups with rasters

Reference GIS QuerySet API Reference Spatial Lookups

All examples in the reference below are given for geometry fields and inputs, but the lookups can be used the same way with rasters on both sides.

bbcontains

Reference GIS QuerySet API Reference Spatial Lookups

Availability: PostGIS, MariaDB, MySQL, SpatiaLite, PGRaster (Native) Tests if the geometry or raster field’s bounding box completely contains the lookup geometry’s bounding box.

bboverlaps

Reference GIS QuerySet API Reference Spatial Lookups

Availability: PostGIS, MariaDB, MySQL, SpatiaLite, PGRaster (Native) Tests if the geometry field’s bounding box overlaps the lookup geometry’s bounding box.

contained

Reference GIS QuerySet API Reference Spatial Lookups

Availability: PostGIS, MariaDB, MySQL, SpatiaLite, PGRaster (Native) Tests if the geometry field’s bounding box is completely contained by the lookup geometry’s bounding box.