djangodocs.org

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

Topic guide Managers

In lieu of the above approach which requires duplicating methods on both the QuerySet and the Manager, QuerySet.as_manager() can be used to create an instance of Manager with a copy of a custom QuerySet’s methods: The Manager instance created by …

dev

Topic guide Multiple databases

If you’re overriding get_queryset() on your manager, be sure to either call the method on the parent (using super()) or do the appropriate handling of the _db attribute on the manager (a string containing the name of the database to …

dev

Caching and QuerySets

Topic guide Making queries

Each QuerySet contains a cache to minimize database access. Understanding how it works will allow you to write the most efficient code. In a newly created QuerySet, the cache is empty.

dev

Topic guide Aggregation Aggregations and other QuerySet clauses

When an aggregation is applied to an empty queryset or grouping, the result defaults to its default parameter, typically None. This behavior occurs because aggregate functions return NULL when the executed query returns no rows.

4.2 5.0 5.1 5.2 6.0

Topic guide Managers Custom managers

While most methods from the standard QuerySet are accessible directly from the Manager, this is only the case for the extra methods defined on a custom QuerySet if you also implement them on the Manager: This example allows you to …

4.2 5.0 5.1 5.2 6.0

Topic guide Managers Custom managers

In lieu of the above approach which requires duplicating methods on both the QuerySet and the Manager, QuerySet.as_manager() can be used to create an instance of Manager with a copy of a custom QuerySet’s methods: The Manager instance created by …

4.2 5.0 5.1 5.2 6.0

Topic guide Multiple databases Manually selecting a databaseUsing managers with multiple databases

If you’re overriding get_queryset() on your manager, be sure to either call the method on the parent (using super()) or do the appropriate handling of the _db attribute on the manager (a string containing the name of the database to …

4.2 5.0 5.1 5.2 6.0

Caching and QuerySets

Topic guide Making queries Retrieving objects

Each QuerySet contains a cache to minimize database access. Understanding how it works will allow you to write the most efficient code. In a newly created QuerySet, the cache is empty.

4.2 5.0 5.1 5.2 6.0

Topic guide Managers

A Manager’s base QuerySet returns all objects in the system. For example, using this model: …the statement Book.objects.all() will return all books in the database. You can override a Manager’s base QuerySet by overriding the Manager.get_queryset() method.

dev