Reference Databases
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.
769 sections in Django dev Search all versions →
Reference Databases
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.
Reference Query Expressions
There are times when a single column must be returned from a Subquery, for instance, to use a Subquery as the target of an __in lookup.
Reference Query Expressions
classRawSQL(sql,params,output_field=None)[source] Sometimes database expressions can’t easily express a complex WHERE clause. In these edge cases, use the RawSQL expression.
Reference Query 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.
Reference Query Expressions
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.
Reference Model field reference
classDateField(auto_now=False,auto_now_add=False,**options)[source] 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.
Reference Model field reference
classField[source] : 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()).
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
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.
Reference Model instance reference
If save() is passed a list of field names in keyword argument update_fields, only the fields named in that list will be updated.
Reference Model instance reference
Otherwise, for database variants such as DB_CASCADE, the return value will report only instances of the QuerySet’s model. For more details, including how to delete objects in bulk, see Deleting objects.
Reference Model instance reference
Model._state : The _state attribute refers to a ModelState object that tracks the lifecycle of the model instance.
Reference Lookup API reference
classLookup[source] : A Lookup is a generic class to implement lookups.
Reference Model Meta options
Options.get_latest_by : The name of a field or a list of field names in the model, typically DateField, DateTimeField, or IntegerField. This specifies the default field(s) to use in your model Manager’s latest() and earliest() methods.
Reference
classRelatedManager : A “related manager” is a manager used in a one-to-many or many-to-many related context. This happens in two cases:
Reference
Using `remove()` with a many-to-many relationship, however, will delete the relationships using [`QuerySet.delete()`](querysets.md#django.db.models.query.QuerySet.delete) which means no model `save()` methods are called; listen to the [`m2m_changed`](../signals.md#django.db.models.signals.m2m_changed) signal if you wish to execute custom code when a relationship is deleted.
Reference Paginator
Paginator.object_list : Required. A list, tuple, QuerySet, or other sliceable object with a count() or __len__() method. For consistent pagination, QuerySets should be ordered, e.g. with an order_by() clause or with a default ordering on the model. Paginator.per_page : Required.
Reference Paginator
Paginator.ELLIPSIS : A translatable string used as a substitute for elided page numbers in the page range returned by get_elided_page_range(). Default is '…'. Paginator.count[source] : The total number of objects, across all pages. Paginator.num_pages[source] : The total number of pages.
Reference Signals
WARNING: For performance reasons, you shouldn’t perform queries in receivers of > pre_init or post_init signals because they would be executed for > each instance returned during queryset iteration.
Reference TemplateResponse and SimpleTemplateResponse
It can also be used as an alternative to calling render(). For example, the following view returns a TemplateResponse with a template and a context containing a queryset: