djangodocs.org

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

Extra instance methods

Reference Model instance reference

In addition to save(), delete(), a model object might have some of the following methods: Model.get_FOO_display() For every field that has choices set, the object will have a get_FOO_display() method, where FOO is the name of the field.

dev

A lookup example

How-to How to write custom lookups

You will need to ensure that this registration happens before you try to create any querysets using it. You could place the implementation in a models.py file, or register the lookup in the ready() method of an AppConfig.

4.2 5.0 5.1 5.2 6.0

A simple example

Reference The syndication feed framework The high-level framework

This simple example, taken from a hypothetical police beat news site describes a feed of the latest five news items: To connect a URL to this feed, put an instance of the Feed object in your URLconf.

4.2 5.0 5.1 5.2 6.0

Extra instance methods

Reference Model instance reference

In addition to save(), delete(), a model object might have some of the following methods: Model.get_FOO_display() For every field that has choices set, the object will have a get_FOO_display() method, where FOO is the name of the field.

4.2 5.0 5.1 5.2 6.0

Topic guide Making queries Querying JSONField

As with other fields, storing None as the field’s value will store it as SQL NULL. While not recommended, it is possible to store JSON scalar null instead of SQL NULL by using Value(None, JSONField()).

4.2 5.0 5.1 5.2 6.0

Topic guide Making queries Querying JSONField

To query based on a given dictionary key, use that key as the lookup name: Multiple keys can be chained together to form a path lookup: If the key is an integer, it will be interpreted as an index transform …

6.0

Topic guide Making queries Querying JSONField

To query based on a given dictionary key, use that key as the lookup name: Multiple keys can be chained together to form a path lookup: If the key is an integer, it will be interpreted as an index transform …

4.2 5.0 5.1 5.2

… 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 Paginator Paginator class AsyncPaginator class Page class AsyncPage …

dev

C

Index

… attribute) - contained - field lookup type - contains - field lookup type - contains() (GEOSGeometry method) - (in module django.db.models.query.QuerySet) - (OGRGeometry method) - (PreparedGeometry method) - contains_aggregate (Expression attribute) - contains_over_clause (Expression attribute) - contains_properly - field lookup …

T

Index

| | | | --- | --- | | - TabularInline (class in django.contrib.admin) - Tan (class in django.db.models.functions) - Task (class in django.tasks) - task (TaskResult attribute) - task() (in module django.tasks) - task_result (TaskContext attribute) - TaskContext (class …

… 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 Paginator Paginator class AsyncPaginator class Page class AsyncPage …

4.2 5.0 5.1 5.2 6.0

values_list()

Reference QuerySet API reference

values_list(*fields,flat=False,named=False) This is similar to values() except that instead of returning dictionaries, it returns tuples when iterated over.

dev

create()

Reference QuerySet API reference

create(**kwargs) acreate(**kwargs) Asynchronous version: acreate() A convenience method for creating an object and saving it all in one step. Thus: and: are equivalent.

dev

bulk_create()

Reference QuerySet API reference

bulk_create(objs,batch_size=None,ignore_conflicts=False,update_conflicts=False,update_fields=None,unique_fields=None) abulk_create(objs,batch_size=None,ignore_conflicts=False,update_conflicts=False,update_fields=None,unique_fields=None) Asynchronous version: abulk_create() This method inserts the provided list of objects into the database in an efficient manner (generally only 1 query, no matter how many objects there are), and returns created objects as a list, in the …

dev

With server-side cursors

Reference QuerySet API reference

Oracle and PostgreSQL use server-side cursors to stream results from the database without loading the entire result set into memory. The Oracle database driver always uses server-side cursors.

dev

exact

Reference QuerySet API reference

Exact match. If the value provided for comparison is None, it will be interpreted as an SQL NULL (see isnull for more details). Key and index lookups are exceptions: they interpret None as JSON null instead.

dev

iexact

Reference QuerySet API reference

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.

dev