mirror of https://github.com/django/django.git
Fixed #29279 -- Added renderer argument to ModelForm.
This commit is contained in:
parent
058f607518
commit
e163effecc
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue