module documentation

Helper functions for creating Form classes from Django models and database field objects.
Class ​Base​Inline​Form​Set A formset for child objects related to a parent.
Class ​Base​Model​Form​Set A FormSet for editing a queryset and/or adding new objects to it.
Function inlineformset​_factory Return an InlineFormSet for the given kwargs.
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
Class ​Base​Model​Form No class docstring; 0/2 instance variable, 4/8 methods documented
Class ​Inline​Foreign​Key​Field A basic integer field that deals with validating the given value to a given parent instance in an inline.
Class ​Model​Choice​Field A ChoiceField whose choices are a model QuerySet.
Class ​Model​Choice​Iterator Undocumented
Class ​Model​Choice​Iterator​Value Undocumented
Class ​Model​Form Undocumented
Class ​Model​Form​Metaclass Undocumented
Class ​Model​Form​Options Undocumented
Class ​Model​Multiple​Choice​Field A MultipleChoiceField whose choices are a model QuerySet.
Function ​_get​_foreign​_key No summary
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 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
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):

Return an InlineFormSet for the given kwargs.

fk_name must be provided if model has more than one ForeignKey to parent_model.

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

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):
Return a FormSet class for the given Django model class.
ALL_FIELDS: str =

Undocumented

Value
'__all__'
def _get_foreign_key(parent_model, model, fk_name=None, can_fail=False):
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):
Apply limit_choices_to to the formfield's queryset if needed.
def construct_instance(form, instance, fields=None, exclude=None):
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):

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 model_to_dict(instance, fields=None, exclude=None):

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

Undocumented