djangodocs.org

680 sections in Django 5.0 Search all versions →

Reference django.contrib.auth Authentication backends

classAllowAllUsersModelBackend : Same as ModelBackend except that it doesn’t reject inactive users because user_can_authenticate() always returns True. classRemoteUserBackend : Use this backend to take advantage of external-to-Django-handled authentication. It authenticates using usernames passed in request.META['REMOTE_USER'].

Reference The contenttypes framework

Each ContentType instance has methods that allow you to get from a ContentType instance to the model it represents, or to retrieve objects from that model: ContentType.get_object_for_this_type(**kwargs) : Takes a set of valid lookup arguments for the model the ContentType …

Spatial Lookups

Reference GeoDjango Tutorial Spatial Queries

[4] Import the WorldBorder model, and perform a contains lookup using the pnt_wkt as the parameter: Here, you retrieved a QuerySet with only one model: the border of the United States (exactly what you would expect).

overlap

Reference PostgreSQL specific model fields Range FieldsQuerying Range FieldsContainment functions

Returns objects where the data shares any results with the values passed. Uses the SQL operator &&. For example: Changed in Django 4.2: Support for QuerySet.values() and values_list() as a right-hand > side was added.

An example

Reference The sitemap framework

items() is a method that returns a sequence or QuerySet of objects. The objects returned will get passed to any callable methods corresponding to a sitemap property (location, lastmod, changefreq, and priority). lastmod should return a datetime.

Isolation level

Reference Databases MySQL notesConnecting to the database

When running concurrent loads, database transactions from different sessions (say, separate threads handling different requests) may interact with each other. These interactions are affected by each session’s transaction isolation level.

TextField limitations

Reference Databases Oracle notes

LOB columns may not be used in a SELECT DISTINCT list. This means that attempting to use the QuerySet.distinct method on a model that includes TextField columns will result in an ORA-00932 error when run against Oracle.

Window functions

Reference Query Expressions Built-in Expressions

You can specify multiple windows in the same query which in Django ORM would be equivalent to including multiple expressions in a QuerySet.annotate() call. The ORM doesn’t make use of named windows, instead they are part of the selected columns.

Expression API

Reference Query Expressions Technical Information

Query expressions implement the query expression API, but also expose a number of extra methods and attributes listed below. All query expressions must inherit from Expression() or a relevant subclass.

Expression API

Reference Query Expressions Technical Information

As an example, an expression implementing `NULLS LAST` would change its value to be `NULLS FIRST`. Modifications are only required for expressions that implement sort order like `OrderBy`. This method is called when [`reverse()`](querysets.md#django.db.models.query.QuerySet.reverse) is called on a queryset.

DateField

Reference Model field reference Field types

classDateField(auto_now=False,auto_now_add=False,**options) A date, represented in Python by a datetime.date instance. Has a few extra, optional arguments: DateField.auto_now : Automatically set the field to now every time the object is saved. Useful for “last-modified” timestamps.

Arguments

Reference Model field reference Relationship fieldsManyToManyField

ForeignKey.limit_choices_to : Sets a limit to the available choices for this field when this field is rendered using a ModelForm or the admin (by default, all objects in the queryset are available to choose).

Field API reference

Reference Model field reference

classField : Field is an abstract class that represents a database table column. Django uses fields to create the database table (db_type()), to map Python types to database (get_prep_value()) and vice-versa (from_db_value()).

Models

Reference

Model field reference Field attribute reference Model index reference Constraints reference Model _meta API Related objects reference Model class reference Model Meta options Model instance reference QuerySet API reference Lookup API reference Query Expressions Conditional Expressions Database Functions

Model instance reference

Reference

This document describes the details of the Model API. It builds on the material presented in the model and database query guides, so you’ll probably want to read and understand those documents before reading this one.

_state

Reference Model instance reference Other attributes

Model._state : The _state attribute refers to a ModelState object that tracks the lifecycle of the model instance.