LibraryActive

Django ORM

Django's database abstraction layer for defining models and querying relational data.

Open source page

Field note

What it does

Django's database abstraction layer for defining models and querying relational data.

Capabilities

Available capabilities

Tags

Tags

Ways to use it

Ways to use it

pypi

Python / Django

Product features

Product features

aggregate()

Terminal clause returning a dictionary of computed aggregate values over a QuerySet.

Aggregate functions

Avg, Max, Min, Count and other functions from django.db.models.

annotate()

Generates an aggregate for each item in a QuerySet as an attribute.

atomic()

Create a block of code guaranteeing atomicity; usable as decorator or context manager, nestable.

ATOMIC_REQUESTS

Wraps each request in a transaction; commits on success, rolls back on exception.

bulk_create() and bulk_update()

Create or update many rows in bulk.

Cast ¶

Coalesce ¶

Collate ¶

Comparison and conversion functions ¶

Database Functions ¶

Date functions ¶

DateField extracts ¶

DateTimeField extracts ¶

default argument

Provide a default returned instead of None when no rows exist.

defer() and only()

Control which fields are loaded from the database.

connection.execute_wrapper()

Returns a context manager that installs a wrapper around database query executions on the thread-local connection.

QuerySet.explain()

Shows how the database executes a query, including indexes and joins.

Extract ¶

F() expressions and annotate()

Do filtering and aggregation work in the database.

Filtered aggregates

Count with filter=Q(...) to aggregate a subset of related rows.

Fixtures

Greatest ¶

QuerySet.iterator()

Reduces memory use when iterating over many objects.

Least ¶

Making queries

Managers

Many-to-many relationships

Model relationship API usage examples for many-to-many relationships.

Many-to-one relationships

Model relationship API usage examples for many-to-one relationships.

Models

A model is the single, definitive source of information about your data.

non_atomic_requests()

Decorator that negates the effect of ATOMIC_REQUESTS for a given view.

NullIf ¶

One-to-one relationships

Model relationship API usage examples for one-to-one relationships.

RawSQL and raw SQL

Add explicit SQL to queries when ORM expressions are insufficient.

select_related() and prefetch_related()

Efficiently retrieve related objects in fewer queries.

Tablespaces

values() and values_list()

Retrieve only needed fields instead of full model instances.

Wrapper parameters

Wrappers receive execute, sql, params, many, and context arguments for each query execution.