djangodocs.org

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

Reference Admin actions

By default, after an action is performed the user is redirected back to the original change list page. However, some actions, especially more complex ones, will need to return intermediate pages.

dev

Reference Admin actions

NOTE: Added in version 6.1. By default, admin actions are available on the change list page only. You can control where an action appears using the location argument of the @admin.action decorator.

dev

The action decorator

Reference Admin actions

action(*,permissions=None,description=None,description_plural=None,location=ActionLocation.CHANGE_LIST)[source] : This decorator can be used for setting specific attributes on custom action functions that can be used with actions:

dev

ModelAdmin options

Reference The Django admin site

ModelAdmin.list_filter : Set list_filter to activate filters in the right sidebar of the change list page of the admin. ModelAdmin.list_max_show_all : Set list_max_show_all to control how many items can appear on a “Show all” admin change list page.

dev

InlineModelAdmin options

Reference The Django admin site

… in the BaseModelAdmin superclass). The shared features are: form fieldsets fields formfield_overrides delete_confirmation_max_display exclude filter_horizontal filter_vertical ordering prepopulated_fields get_exclude() get_fieldsets() get_queryset() radio_fields readonly_fields view_on_site empty_value_display autocomplete_fields raw_id_fields formfield_for_choice_field() formfield_for_foreignkey() formfield_for_manytomany() has_module_permission() The InlineModelAdmin class adds or customizes: InlineModelAdmin.model : The …

dev

AdminSite methods

Reference The Django admin site

Raises django.contrib.admin.exceptions.NotRegistered if a model isn’t registered. AdminSite.get_log_entries(request)[source] : Returns a queryset for the related LogEntry instances, shown on the site index page. This method can be overridden to filter the log entries by other criteria.

dev

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(using=None,**kwargs)[source] : Takes a set of valid lookup arguments for the model the ContentType …

dev

Spatial Lookups

Reference GeoDjango Tutorial

[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 instance: the border of the United States (exactly what you would expect).

dev

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.

dev

Isolation level

Reference Databases

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.

dev

TextField limitations

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.

dev

Raw SQL expressions

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.

dev

Window functions

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.

dev

Expression API

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.

dev

DateField

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.

dev

Field API reference

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()).

dev

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

dev