djangodocs.org

256 sections in Django dev Search all versions →

Models

Release notes Django 2.0 release notes What’s new in Django 2.0Minor features

It may be helpful particularly when select_for_update() is used in conjunction with select_related(). The new field_name parameter of QuerySet.in_bulk() allows fetching results based on any unique model field.

Bugfixes

Release notes Django 4.2.2 release notes

Fixed a regression in Django 4.2 that caused a serialization crash on a ManyToManyField without a natural key when its Manager’s base QuerySet used select_related() (#34620).

Models

Release notes Django 5.1 release notes What’s new in Django 5.1Minor features

QuerySet.explain() now supports the generic_plan option on PostgreSQL 16+. RowRange now accepts positive integers for the start argument and negative integers for the end argument.

ModelAdmin options

Reference The Django admin site ModelAdmin objects

ModelAdmin.raw_id_fields : By default, Django’s admin uses a select-box interface (<select>) for fields that are ForeignKey. Sometimes you don’t want to incur the overhead of having to select all the related instances to display in the drop-down.

InlineModelAdmin options

Reference The Django admin site InlineModelAdmin objects

InlineModelAdmin.max_num : This controls the maximum number of forms to show in the inline. This doesn’t directly correlate to the number of objects, but can if the value is small enough.

distinct()

Reference QuerySet API reference QuerySet APIMethods that return new QuerySets

distinct(*fields) Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results. By default, a QuerySet will not eliminate duplicate rows.

1.10

Internals Django Deprecation Timeline

ALLOWED_INCLUDE_ROOTS TEMPLATE_CONTEXT_PROCESSORS TEMPLATE_DEBUG TEMPLATE_DIRS TEMPLATE_LOADERS TEMPLATE_STRING_IF_INVALID The backwards compatibility alias django.template.loader.BaseLoader will be removed. Django template objects returned by get_template() and select_template() won’t accept a Context in their render() method anymore.

Topic guide Making queries Retrieving objectsLookups that span relationships

When spanning a ManyToManyField or a reverse ForeignKey (such as from Blog to Entry), filtering on multiple attributes raises the question of whether to require each attribute to coincide in the same related object.

PostgreSQL support

Topic guide Search Use CasesDocument-based search

PostgreSQL has its own full text search implementation built-in. While not as powerful as some other search engines, it has the advantage of being inside your database and so can easily be combined with other relational queries such as categorization.

values()

Reference QuerySet API reference QuerySet APIMethods that return new QuerySets

values(*fields,**expressions) Returns a QuerySet that returns dictionaries, rather than model instances, when used as an iterable. Each of those dictionaries represents an object, with the keys corresponding to the attribute names of model objects.

values()

Reference QuerySet API reference QuerySet APIMethods that return new QuerySets

For example: When using values() together with distinct(), be aware that ordering can affect the results. See the note in distinct() for details.

update()

Reference QuerySet API reference QuerySet APIMethods that do not return QuerySets

update(**kwargs) aupdate(**kwargs) Asynchronous version: aupdate() Performs an SQL update query for the specified fields, and returns the number of rows matched (which may not be equal to the number of rows updated if some rows already have the new value).

Field options

Topic guide Models Fields

Each field takes a certain set of field-specific arguments (documented in the model field reference). For example, CharField (and its subclasses) require a max_length argument which specifies the size of the VARCHAR database field used to store the data.

Topic guide Models FieldsRelationships

To define a many-to-many relationship, use ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model. ManyToManyField requires a positional argument: the class to which the model is related.

1.10

Internals Django Deprecation Timeline

See the Django 1.8 release notes for more details on these changes. Support for calling a SQLCompiler directly as an alias for calling its quote_name_unless_alias method will be removed.

ModelAdmin options

Reference The Django admin site ModelAdmin objects

ModelAdmin.prepopulated_fields : Set prepopulated_fields to a dictionary mapping field names to the fields it should prepopulate from: ModelAdmin.preserve_filters : By default, applied filters are preserved on the list view after creating, editing, or deleting an object.

C

Index

| | | | --- | --- | | - cache - template tag - cache_control() (in module django.views.decorators.cache) - cache_key_prefix (backends.cached_db.SessionStore attribute) - CACHE_MIDDLEWARE_ALIAS - setting - CACHE_MIDDLEWARE_KEY_PREFIX - setting - CACHE_MIDDLEWARE_SECONDS - setting - cached.Loader (class in django.template.loaders) …

Bugfixes

Release notes Django 2.2.11 release notes

Fixed a data loss possibility in the select_for_update(). When using related fields or parent link fields with Multi-table inheritance in the of argument, the corresponding models were not locked (#31246).

Bugfixes

Release notes Django 2.2.16 release notes

Fixed a data loss possibility in the select_for_update(). When using related fields pointing to a proxy model in the of argument, the corresponding model was not locked (#31866).