djangodocs.org

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

AND (&)

Reference QuerySet API reference QuerySet APIOperators that return new QuerySets

Combines two QuerySets using the SQL AND operator in a manner similar to chaining filters. The following are equivalent: SQL equivalent:

4.2 5.0 5.1 5.2 6.0

OR (|)

Reference QuerySet API reference QuerySet APIOperators that return new QuerySets

Combines two QuerySets using the SQL OR operator. The following are equivalent: SQL equivalent: | is not a commutative operation, as different (though equivalent) queries may be generated.

4.2 5.0 5.1 5.2 6.0

XOR (^)

Reference QuerySet API reference QuerySet APIOperators that return new QuerySets

Combines two QuerySets using the SQL XOR operator. A XOR expression matches rows that are matched by an odd number of operands. The following are equivalent: SQL equivalent: NOTE: XOR is natively supported on MariaDB and MySQL.

4.2 5.0 5.1 5.2 6.0

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.

4.2 5.0 5.1 5.2 6.0

exact

Reference QuerySet API reference QuerySet APIField lookups

Exact match. If the value provided for comparison is None, it will be interpreted as an SQL NULL (see isnull for more details).

4.2 5.0 5.1 5.2 6.0

iexact

Reference QuerySet API reference QuerySet APIField lookups

Case-insensitive exact match. If the value provided for comparison is None, it will be interpreted as an SQL NULL (see isnull for more details). Example: SQL equivalents: Note the first query will match 'Beatles Blog', 'beatles blog', 'BeAtLes BLoG', etc.

4.2 5.0 5.1 5.2 6.0

year

Reference QuerySet API reference QuerySet APIField lookups

For date and datetime fields, an exact year match. Allows chaining additional field lookups. Takes an integer year.

4.2 5.0 5.1 5.2 6.0

month

Reference QuerySet API reference QuerySet APIField lookups

For date and datetime fields, an exact month match. Allows chaining additional field lookups. Takes an integer 1 (January) through 12 (December).

4.2 5.0 5.1 5.2 6.0

day

Reference QuerySet API reference QuerySet APIField lookups

For date and datetime fields, an exact day match. Allows chaining additional field lookups. Takes an integer day.

4.2 5.0 5.1 5.2 6.0

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.

4.2 5.0 5.1 5.2 6.0

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.

4.2 5.0 5.1 5.2 6.0

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.

4.2 5.0 5.1 5.2 6.0

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:

4.2 5.0 5.1 5.2 6.0

Topic guide Making queries Retrieving objects

The QuerySet returned by all() describes all objects in the database table. Usually, though, you’ll need to select only a subset of the complete set of objects. To create such a subset, you refine the initial QuerySet, adding filter conditions.

4.2 5.0 5.1 5.2 6.0