From c94fcc4117987c4ebe29ad63da01035230c8afd5 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Fri, 11 Jan 2013 05:59:17 -0500 Subject: [1.5.x] Fixed #10239 - Added docs for modelform_factory Thanks ingenieroariel for the suggestion and slurms for the review. Backport of 71d76ec011 from master --- django/forms/models.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'django/forms') diff --git a/django/forms/models.py b/django/forms/models.py index 27c246b668..1b6821cd5b 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -141,6 +141,11 @@ def fields_for_model(model, fields=None, exclude=None, widgets=None, formfield_c ``exclude`` is an optional list of field names. If provided, the named fields will be excluded 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. """ field_list = [] ignored = [] @@ -371,6 +376,21 @@ class ModelForm(six.with_metaclass(ModelFormMetaclass, BaseModelForm)): def modelform_factory(model, form=ModelForm, fields=None, exclude=None, formfield_callback=None, widgets=None): + """ + Returns a ModelForm containing form fields for the given model. + + ``fields`` is an optional list of field names. If provided, only the named + fields will be included in the returned fields. + + ``exclude`` is an optional list of field names. If provided, the named + fields will be excluded 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. + """ # Create the inner Meta class. FIXME: ideally, we should be able to # construct a ModelForm without creating and passing in a temporary # inner class. -- cgit v1.3