module documentation

Helper functions for creating Form classes from Django models and database field objects.

Class BaseInlineFormSet A formset for child objects related to a parent.
Class BaseModelForm No class docstring; 0/2 instance variable, 4/8 methods documented
Class BaseModelFormSet A ``FormSet`` for editing a queryset and/or adding new objects to it.
Class InlineForeignKeyField A basic integer field that deals with validating the given value to a given parent instance in an inline.
Class ModelChoiceField A ChoiceField whose choices are a model QuerySet.
Class ModelChoiceIterator Undocumented
Class ModelChoiceIteratorValue Undocumented
Class ModelForm Undocumented
Class ModelFormMetaclass Undocumented
Class ModelFormOptions Undocumented
Class ModelMultipleChoiceField A MultipleChoiceField whose choices are a model QuerySet.
Function apply_limit_choices_to_to_formfield Apply limit_choices_to to the formfield's queryset if needed.
Function construct_instance Construct and return a model instance from the bound ``form``'s ``cleaned_data``, but do not save the returned instance to the database.
Function fields_for_model Return a dictionary containing form fields for the given model.
Function inlineformset_factory Return an ``InlineFormSet`` for the given kwargs.
Function model_to_dict Return a dict containing the data in ``instance`` suitable for passing as a Form's ``initial`` keyword argument.
Function modelform_defines_fields Undocumented
Function modelform_factory Return a ModelForm containing form fields for the given model. You can optionally pass a `form` argument to use as a starting point for constructing the ModelForm.
Function modelformset_factory Return a FormSet class for the given Django model class.
Constant ALL_FIELDS Undocumented
Function _get_foreign_key Find and return the ForeignKey from model to parent if there is one (return None if can_fail is True and no such field exists). If fk_name is provided, assume it is the name of the ForeignKey field. Unless can_fail is True, raise an exception if there isn't a ForeignKey from model to parent_model.
def apply_limit_choices_to_to_formfield(formfield): (source)

Apply limit_choices_to to the formfield's queryset if needed.

def construct_instance(form, instance, fields=None, exclude=None): (source)

Construct and return a model instance from the bound ``form``'s ``cleaned_data``, but do not save the returned instance to the database.

def fields_for_model(model, fields=None, exclude=None, widgets=None, formfield_callback=None, localized_fields=None, labels=None, help_texts=None, error_messages=None, field_classes=None, *, apply_limit_choices_to=True): (source)

Return a dictionary containing form fields for the given model. ``fields`` is an optional list of field names. If provided, return only the named fields. ``exclude`` is an optional list of field names. If provided, exclude the named fields from the returned fields, even if they are listed in the ``fields`` argument. ``widgets`` is a dictionary of model field names mapped to a widget. ``formfield_callback`` is a callable that takes a model field and returns a form field. ``localized_fields`` is a list of names of fields which should be localized. ``labels`` is a dictionary of model field names mapped to a label. ``help_texts`` is a dictionary of model field names mapped to a help text. ``error_messages`` is a dictionary of model field names mapped to a dictionary of error messages. ``field_classes`` is a dictionary of model field names mapped to a form field class. ``apply_limit_choices_to`` is a boolean indicating if limit_choices_to should be applied to a field's queryset.

def 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)

Return an ``InlineFormSet`` for the given kwargs. ``fk_name`` must be provided if ``model`` has more than one ``ForeignKey`` to ``parent_model``.

def model_to_dict(instance, fields=None, exclude=None): (source)

Return a dict containing the data in ``instance`` suitable for passing as a Form's ``initial`` keyword argument. ``fields`` is an optional list of field names. If provided, return only the named. ``exclude`` is an optional list of field names. If provided, exclude the named from the returned dict, even if they are listed in the ``fields`` argument.

def modelform_defines_fields(form_class): (source)

Undocumented

def modelform_factory(model, form=ModelForm, fields=None, exclude=None, formfield_callback=None, widgets=None, localized_fields=None, labels=None, help_texts=None, error_messages=None, field_classes=None): (source)

Return a ModelForm containing form fields for the given model. You can optionally pass a `form` argument to use as a starting point for constructing the ModelForm. ``fields`` is an optional list of field names. If provided, include only the named fields in the returned fields. If omitted or '__all__', use all fields. ``exclude`` is an optional list of field names. If provided, exclude the named fields from the returned fields, even if they are listed in the ``fields`` argument. ``widgets`` is a dictionary of model field names mapped to a widget. ``localized_fields`` is a list of names of fields which should be localized. ``formfield_callback`` is a callable that takes a model field and returns a form field. ``labels`` is a dictionary of model field names mapped to a label. ``help_texts`` is a dictionary of model field names mapped to a help text. ``error_messages`` is a dictionary of model field names mapped to a dictionary of error messages. ``field_classes`` is a dictionary of model field names mapped to a form field class.

def modelformset_factory(model, form=ModelForm, formfield_callback=None, formset=BaseModelFormSet, extra=1, can_delete=False, can_order=False, max_num=None, fields=None, exclude=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)

Return a FormSet class for the given Django model class.

ALL_FIELDS: str = (source)

Undocumented

Value
'__all__'
def _get_foreign_key(parent_model, model, fk_name=None, can_fail=False): (source)

Find and return the ForeignKey from model to parent if there is one (return None if can_fail is True and no such field exists). If fk_name is provided, assume it is the name of the ForeignKey field. Unless can_fail is True, raise an exception if there isn't a ForeignKey from model to parent_model.