Changes between Initial Version and Version 3 of Ticket #18166
- 04/24/12 09:05:43 (5 years ago)
- Property Needs documentation set
- Property Needs tests set
initial v3 1 When we use a formset, each form is instantiated by the method BaseFormSet._construct_forms(), which is called from BaseFormSet.__init__() 1 When we use a formset, each form is instantiated by the method 2 2 3 _construct_forms() allows for additional kwargs to be passed through to the individual form constructor, but BaseFormSet.__init__() does not provide any mechanism for kwargs to be passed through to the _construct_forms()call. 3 call. 4 4 5 5 Also, we may not be able to supply a static unchanging list of kwargs that should be supplied to each form constructor - the kwargs we want to pass may depend upon the specific instance of the form being instantiated. … … 7 7 I propose the following changes: 8 8 9 Add a form_kwargs argument to BaseFormSet.__init__(). This would be stored on self, and consumed in BaseFormSet._construct_forms() 9 Add a 10 10 11 Add a method, BaseFormSet._kwargs_for_form(self, i). This method would be called for each form instantiated, passing the index of the form within the formset. The return value of this method would be merged with the form_kwargs supplied in BaseFormSet.__init__()and used to instantiate the form. 11 Add a method, and used to instantiate the form. 12 12 13 13 With these changes, a user could add additional constructor arguments to all forms by passing in form_kwargs to the formset constructor, and could add additional constructor arguments to specific forms by implementing _kwargs_for_form on a derived BaseFormSet class. 14 14 15 (I found it strange, when BaseFormSet was written, it was clearly intended to be able to pass kwargs to the forms - _construct_form() allows for it, there just is not the plumbing to do so. I worked around this by redefining - copy/pasting - the _construct_forms() method in my derived BaseFormSetclass) 15 (I found it strange, when class) 16 16 17 17 Patch doesn't have tests or doc changes, will add if this idea gets traction.