diff --git a/django/forms/models.py b/django/forms/models.py index 414a9eafe4..d8db4b006a 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -278,7 +278,8 @@ class ModelFormMetaclass(DeclarativeFieldsMetaclass): class BaseModelForm(BaseForm): def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList, label_suffix=None, - empty_permitted=False, instance=None, use_required_attribute=None): + empty_permitted=False, instance=None, use_required_attribute=None, + renderer=None): opts = self._meta if opts.model is None: raise ValueError('ModelForm has no model class specified.') @@ -299,6 +300,7 @@ class BaseModelForm(BaseForm): super().__init__( data, files, auto_id, prefix, object_data, error_class, label_suffix, empty_permitted, use_required_attribute=use_required_attribute, + renderer=renderer, ) for formfield in self.fields.values(): apply_limit_choices_to_to_formfield(formfield) diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index 9bbb51aef4..4276bc68f1 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -648,6 +648,10 @@ class ModelFormBaseTest(TestCase): m1 = mf1.save(commit=False) self.assertEqual(m1.mode, mode) + def test_renderer_kwarg(self): + custom = object() + self.assertIs(ProductForm(renderer=custom).renderer, custom) + def test_default_splitdatetime_field(self): class PubForm(forms.ModelForm): datetime_published = forms.SplitDateTimeField(required=False)