djangodocs.org

256 sections in Django dev Search all versions →

Reference Databases MySQL notes

MySQL and MariaDB do not support some options to the SELECT ... FOR UPDATE statement. If select_for_update() is used with an unsupported option, then a NotSupportedError is raised.

extra()

Reference QuerySet API reference QuerySet APIMethods that return new QuerySets

extra(select=None,where=None,params=None,tables=None,order_by=None,select_params=None) Sometimes, the Django query syntax by itself can’t easily express a complex WHERE clause. For these edge cases, Django provides the extra() QuerySet modifier — a hook for injecting specific clauses into the SQL generated by a QuerySet.

extra()

Reference QuerySet API reference QuerySet APIMethods that return new QuerySets

The resulting SQL of the above example would be: Note that the parentheses required by most database engines around subqueries are not required in Django’s select clauses.

Topic guide Translation Internationalization: in template code

If you want to select a language within a template, you can use the language template tag: While the first occurrence of “Welcome to our page” uses the current language, the second will always be in English.

ChoiceField

Reference Form fields Built-in Field classes

classChoiceField(**kwargs)[source] : - Default widget: Select - Empty value: '' (an empty string) - Normalizes to: A string. - Validates that the given value exists in the list of choices. - Error message keys: required, invalid_choice

FilePathField

Reference Form fields Built-in Field classes

classFilePathField(**kwargs)[source] : - Default widget: Select - Empty value: '' (an empty string) - Normalizes to: A string. - Validates that the selected choice exists in the list of choices. - Error message keys: required, invalid_choice

ModelChoiceField

Reference Form fields Fields which handle relationships

classModelChoiceField(**kwargs)[source] : - Default widget: Select - Empty value: None - Normalizes to: A model instance. - Validates that the given id exists in the queryset. - Error message keys: required, invalid_choice

NullBooleanSelect

Reference Widgets Built-in widgetsSelector and checkbox widgets

classNullBooleanSelect[source] : - template_name: 'django/forms/widgets/select.html' - option_template_name: 'django/forms/widgets/select_option.html'

SelectMultiple

Reference Widgets Built-in widgetsSelector and checkbox widgets

classSelectMultiple[source] : - template_name: 'django/forms/widgets/select.html' - option_template_name: 'django/forms/widgets/select_option.html'

CheckboxSelectMultiple

Reference Widgets Built-in widgetsSelector and checkbox widgets

classCheckboxSelectMultiple[source] : - template_name: 'django/forms/widgets/checkbox_select.html' - option_template_name: 'django/forms/widgets/checkbox_option.html' Like RadioSelect, you can loop over the individual checkboxes for the widget’s choices.

contains

Reference QuerySet API reference QuerySet APIField lookups

Case-sensitive containment test. Example: SQL equivalent: (The exact SQL syntax varies for each database engine.) Note this will match the headline 'Lennon honored today' but not 'lennon honored today'.

icontains

Reference QuerySet API reference QuerySet APIField lookups

Case-insensitive containment test. Example: SQL equivalent: (The exact SQL syntax varies for each database engine.) NOTE: When using the SQLite backend and non-ASCII strings, bear in mind the > database note about string comparisons.

startswith

Reference QuerySet API reference QuerySet APIField lookups

Case-sensitive starts-with. Example: SQL equivalent: (The exact SQL syntax varies for each database engine.) SQLite doesn’t support case-sensitive LIKE statements; startswith acts like istartswith for SQLite.

istartswith

Reference QuerySet API reference QuerySet APIField lookups

Case-insensitive starts-with. Example: SQL equivalent: (The exact SQL syntax varies for each database engine.) NOTE: When using the SQLite backend and non-ASCII strings, bear in mind the > database note about string comparisons.

endswith

Reference QuerySet API reference QuerySet APIField lookups

Case-sensitive ends-with. Example: SQL equivalent: (The exact SQL syntax varies for each database engine.) NOTE: SQLite doesn’t support case-sensitive LIKE statements; endswith > acts like iendswith for SQLite. Refer to the database note documentation for more.

iendswith

Reference QuerySet API reference QuerySet APIField lookups

Case-insensitive ends-with. Example: SQL equivalent: (The exact SQL syntax varies for each database engine.) NOTE: When using the SQLite backend and non-ASCII strings, bear in mind the > database note about string comparisons.

USE_BLANK_CHOICE_DASH

Reference Settings Core Settings

New in Django 6.1. Default: False The default blank choice label in Select widgets was changed from "---------" to django.db.models.fields.BLANK_CHOICE_LABEL. Set this transitional setting to True to revert to the previous label.

Deferring model fields

Topic guide Performing raw SQL queries Performing raw queries

Fields may also be left out: The Person objects returned by this query will be deferred model instances (see defer()). This means that the fields that are omitted from the query will be loaded on demand.