djangodocs.org

713 sections in Django 6.0 Search all versions →

template_name

Reference Form fields Core field arguments

By default this value is set to "django/forms/field.html". Can be changed per field by overriding this attribute or more generally by overriding the default template, see also Overriding built-in field templates.

DateField

Reference Form fields Built-in Field classes

- Validates that the given value is either a datetime.date, datetime.datetime or string formatted in a particular date format. - Error message keys: required, invalid

DateTimeField

Reference Form fields Built-in Field classes

- Validates that the given value is either a datetime.datetime, datetime.date or string formatted in a particular datetime format. - Error message keys: required, invalid

DurationField

Reference Form fields Built-in Field classes

classDurationField(**kwargs)[source] : - Default widget: TextInput - Empty value: None - Normalizes to: A Python timedelta. - Validates that the given value is a string which can be converted into a timedelta. The value must be between datetime.timedelta.min and datetime.timedelta.max.

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

GenericIPAddressField

Reference Form fields Built-in Field classes

classGenericIPAddressField(**kwargs)[source] : A field containing either an IPv4 or an IPv6 address.

MultipleChoiceField

Reference Form fields Built-in Field classes

classMultipleChoiceField(**kwargs)[source] : - Default widget: SelectMultiple - Empty value: [] (an empty list) - Normalizes to: A list of strings. - Validates that every value in the given list of values exists in the list of choices.

TimeField

Reference Form fields Built-in Field classes

- Validates that the given value is either a datetime.time or string formatted in a particular time format. - Error message keys: required, invalid

TypedMultipleChoiceField

Reference Form fields Built-in Field classes

classTypedMultipleChoiceField(**kwargs)[source] : Just like a MultipleChoiceField, except TypedMultipleChoiceField takes two extra arguments, coerce and empty_value.

UUIDField

Reference Form fields Built-in Field classes

classUUIDField(**kwargs)[source] : - Default widget: TextInput - Empty value: None - Normalizes to: A UUID object. - Error message keys: required, invalid

SplitDateTimeField

Reference Form fields Slightly complex built-in Field classes

- Validates that the given value is a datetime.datetime or string formatted in a particular datetime format. - Error message keys: required, invalid, invalid_date, invalid_time

ModelMultipleChoiceField

Reference Form fields Fields which handle relationships

classModelMultipleChoiceField(**kwargs)[source] : - Default widget: SelectMultiple - Empty value: An empty QuerySet (self.queryset.none()) - Normalizes to: A QuerySet of model instances. - Validates that every id in the given list of values exists in the queryset.

Reference Form fields Fields which handle relationships

By default, ModelChoiceField and ModelMultipleChoiceField use ModelChoiceIterator to generate their field choices. When iterated, ModelChoiceIterator yields 2-tuple choices containing ModelChoiceIteratorValue instances as the first value element in each choice.

ModelChoiceIterator

Reference Form fields Fields which handle relationshipsIterating relationship choices

classModelChoiceIterator(field)[source] : The default class assigned to the iterator attribute of ModelChoiceField and ModelMultipleChoiceField. An iterable that yields 2-tuple choices from the queryset.

ModelChoiceIteratorValue

Reference Form fields Fields which handle relationshipsIterating relationship choices

classModelChoiceIteratorValue(value,instance)[source] : Two arguments are required:

extend

Topic guide Form Assets (the Media class) Assets as a static definition

A boolean defining inheritance behavior for Media declarations. By default, any object using a static Media definition will inherit all the assets associated with the parent widget. This occurs regardless of how the parent defines its own requirements.

Topic guide Form Assets (the Media class)

If you need to perform some more sophisticated manipulation of asset requirements, you can define the media property directly. This is done by defining a widget property that returns an instance of forms.Media.