djangodocs.org

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

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.

Paths as strings

Topic guide Form Assets (the Media class) Paths in asset definitions

String paths used to specify assets can be either relative or absolute. If a path starts with /, http:// or https://, it will be interpreted as an absolute path, and left as-is.

Paths as objects

Topic guide Form Assets (the Media class) Paths in asset definitions

Assets may also be object-based, using Script. Furthermore, these allow you to pass custom HTML attributes: If this Media definition were to be rendered, it would become the following HTML: Changed in Django 5.2: The object class Script was added.

5.2 6.0 dev

Paths as objects

Topic guide Form Assets (the Media class) Paths in asset definitions

Asset paths may also be given as hashable objects implementing an __html__() method. The __html__() method is typically added using the html_safe() decorator. The object is responsible for outputting the complete HTML <script> or <link> tag content:

4.2 5.0 5.1

Reference The form rendering API

This is a dictionary that contains values like: name value attrs is_hidden template_name Some widgets add further information to the context. For instance, all widgets that subclass Input defines widget['type'] and MultiWidget defines widget['subwidgets'] for looping purposes.

inlineformset_factory

Reference Model forms Model form factory functions

inlineformset_factory(parent_model,model,form=ModelForm,formset=BaseInlineFormSet,fk_name=None,fields=None,exclude=None,extra=3,can_order=False,can_delete=True,max_num=None,formfield_callback=None,widgets=None,validate_max=False,localized_fields=None,labels=None,help_texts=None,error_messages=None,min_num=None,validate_min=False,field_classes=None,absolute_max=None,can_delete_extra=True,renderer=None,edit_only=False)[source] : Returns an InlineFormSet using modelformset_factory() with defaults of formset=BaseInlineFormSet, can_delete=True, and extra=3.

Range Fields

Reference PostgreSQL specific form fields and widgets Fields

This group of fields all share similar functionality for accepting range data. They are based on MultiValueField. They treat one omitted value as an unbounded range. They also validate that the lower bound is not greater than the upper bound.