mirror of
https://github.com/django/django.git
synced 2025-07-04 01:39:20 +00:00
newforms-admin: Allow an overridden _construct_form to easily pass parameters through to the form constructor in formsets.
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7855 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
21974955c4
commit
84541cd244
@ -78,23 +78,24 @@ class BaseFormSet(StrAndUnicode):
|
|||||||
for i in xrange(self._total_form_count):
|
for i in xrange(self._total_form_count):
|
||||||
self.forms.append(self._construct_form(i))
|
self.forms.append(self._construct_form(i))
|
||||||
|
|
||||||
def _construct_form(self, i):
|
def _construct_form(self, i, **kwargs):
|
||||||
"""
|
"""
|
||||||
Instantiates and returns the i-th form instance in a formset.
|
Instantiates and returns the i-th form instance in a formset.
|
||||||
"""
|
"""
|
||||||
kwargs = {'auto_id': self.auto_id, 'prefix': self.add_prefix(i)}
|
defaults = {'auto_id': self.auto_id, 'prefix': self.add_prefix(i)}
|
||||||
if self.data or self.files:
|
if self.data or self.files:
|
||||||
kwargs['data'] = self.data
|
defaults['data'] = self.data
|
||||||
kwargs['files'] = self.files
|
defaults['files'] = self.files
|
||||||
if self.initial:
|
if self.initial:
|
||||||
try:
|
try:
|
||||||
kwargs['initial'] = self.initial[i]
|
defaults['initial'] = self.initial[i]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
# Allow extra forms to be empty.
|
# Allow extra forms to be empty.
|
||||||
if i >= self._initial_form_count:
|
if i >= self._initial_form_count:
|
||||||
kwargs['empty_permitted'] = True
|
defaults['empty_permitted'] = True
|
||||||
form = self.form(**kwargs)
|
defaults.update(kwargs)
|
||||||
|
form = self.form(**defaults)
|
||||||
self.add_fields(form, i)
|
self.add_fields(form, i)
|
||||||
return form
|
return form
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user