diff --git a/django/forms/models.py b/django/forms/models.py
index b34f4d0..db9f059 100644
a
|
b
|
class ModelForm(BaseModelForm):
|
368 | 368 | __metaclass__ = ModelFormMetaclass |
369 | 369 | |
370 | 370 | def modelform_factory(model, form=ModelForm, fields=None, exclude=None, |
371 | | formfield_callback=None): |
| 371 | widgets=None, formfield_callback=None): |
372 | 372 | # Create the inner Meta class. FIXME: ideally, we should be able to |
373 | 373 | # construct a ModelForm without creating and passing in a temporary |
374 | 374 | # inner class. |
… |
… |
def modelform_factory(model, form=ModelForm, fields=None, exclude=None,
|
379 | 379 | attrs['fields'] = fields |
380 | 380 | if exclude is not None: |
381 | 381 | attrs['exclude'] = exclude |
| 382 | if widgets is not None: |
| 383 | attrs['widgets'] = widgets |
382 | 384 | |
383 | 385 | # If parent form class already has an inner Meta, the Meta we're |
384 | 386 | # creating needs to inherit from the parent's inner meta. |
diff --git a/tests/regressiontests/model_forms_regress/tests.py b/tests/regressiontests/model_forms_regress/tests.py
index 9817858..5fdcee9 100644
a
|
b
|
class FormFieldCallbackTests(TestCase):
|
275 | 275 | Form = modelform_factory(Person, form=BaseForm) |
276 | 276 | self.assertTrue(Form.base_fields['name'].widget is widget) |
277 | 277 | |
| 278 | def test_factory_with_widget_argument(self): |
| 279 | """ Regression for #15315: modelform_factory should accept widgets |
| 280 | argument |
| 281 | """ |
| 282 | widget = forms.Textarea() |
| 283 | |
| 284 | # Without a widget should not set the widget to textarea |
| 285 | Form = modelform_factory(Person) |
| 286 | assert Form.base_fields['name'].widget is not widget |
| 287 | |
| 288 | # With a widget should not set the widget to textarea |
| 289 | Form = modelform_factory(Person, widgets={'name':widget}) |
| 290 | self.assertTrue(Form.base_fields['name'].widget is widget) |
| 291 | |
278 | 292 | def test_custom_callback(self): |
279 | 293 | """Test that a custom formfield_callback is used if provided""" |
280 | 294 | |