diff --git a/django/forms/models.py b/django/forms/models.py
index b34f4d0..3c2530a 100644
a
|
b
|
def fields_for_model(model, fields=None, exclude=None, widgets=None, formfield_c
|
139 | 139 | ``exclude`` is an optional list of field names. If provided, the named |
140 | 140 | fields will be excluded from the returned fields, even if they are listed |
141 | 141 | in the ``fields`` argument. |
| 142 | |
| 143 | ``widgets`` is a dictionary of model field names mapped to a widget |
| 144 | |
| 145 | ``formfield_callback`` is a callable that takes a model field and returns |
| 146 | a form field. |
142 | 147 | """ |
143 | 148 | field_list = [] |
144 | 149 | ignored = [] |
… |
… |
class ModelForm(BaseModelForm):
|
369 | 374 | |
370 | 375 | def modelform_factory(model, form=ModelForm, fields=None, exclude=None, |
371 | 376 | formfield_callback=None): |
| 377 | """ |
| 378 | Returns a ``SortedDict`` containing form fields for the given model. |
| 379 | |
| 380 | ``fields`` is an optional list of field names. If provided, only the named |
| 381 | fields will be included in the returned fields. |
| 382 | |
| 383 | ``exclude`` is an optional list of field names. If provided, the named |
| 384 | fields will be excluded from the returned fields, even if they are listed |
| 385 | in the ``fields`` argument. |
| 386 | |
| 387 | ``widgets`` is a dictionary of model field names mapped to a widget |
| 388 | |
| 389 | ``formfield_callback`` is a callable that takes a model field and returns |
| 390 | a form field. |
| 391 | """ |
372 | 392 | # Create the inner Meta class. FIXME: ideally, we should be able to |
373 | 393 | # construct a ModelForm without creating and passing in a temporary |
374 | 394 | # inner class. |
diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt
index 6d418a2..be335b6 100644
a
|
b
|
for more on how field cleaning and validation work. Also, your model's
|
533 | 533 | :ref:`Validating objects <validating-objects>` for more information on the |
534 | 534 | model's ``clean()`` hook. |
535 | 535 | |
| 536 | ModelForm factory function |
| 537 | -------------------------- |
| 538 | |
| 539 | You can create forms from a given model using the standalone function |
| 540 | ``modelformset_factory``, instead of using a class definition. This |
| 541 | may be more convenient if you do not have many customisations to make:: |
| 542 | |
| 543 | >>> from django.forms.models import modelform_factory |
| 544 | >>> BookForm = modelform_factory(Book) |
| 545 | |
| 546 | This can also be used to make simple modifications to existing forms, for |
| 547 | example by specifying which fields should be displayed:: |
| 548 | |
| 549 | >>> Form = modelform_factory(Book, form=BookForm, fields=("author",)) |
| 550 | |
| 551 | ... or which fields should be excluded:: |
| 552 | |
| 553 | >>> Form = modelform_factory(Book, form=BookForm, exclude=("title",)) |
| 554 | |
| 555 | You can also specify the widgets to be used for a given field:: |
| 556 | |
| 557 | >>> from django.forms import Textarea |
| 558 | >>> Form = modelform_factory(Book, form=BookForm, widgets={"title": Textarea()}) |
| 559 | |
536 | 560 | .. _model-formsets: |
537 | 561 | |
538 | 562 | Model formsets |