#35949: Add formset_kwargs keyword argument to BaseFormSet
-------------------------------------+-------------------------------------
     Reporter:  richardbrockie       |                     Type:  New
                                     |  feature
       Status:  new                  |                Component:  Forms
      Version:  5.1                  |                 Severity:  Normal
     Keywords:  formset validation   |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
 Hi,

 I find it useful when validating formsets to sometimes define and set an
 attribute that can be used during validation.

 {{{
 class MyFormSet(BaseFormSet):
     useful_attribute = None

     def clean(self):
         super().clean()

         # validation code using self.useful_attribute...


 # usage in a view...

     the_formset = formset_factory(MyForm, formset=MyFormSet, extra=0)

     bound_formset = the_formset(initial=initial_results,
         form_kwargs=form_kwargs)

     bound_formset.useful_attribute = useful_value
 }}}

 I'm wondering if formset_kwargs could be added to BaseFormSet to follow
 the form_kwargs pattern. The suggested usage would be something like this:

 {{{
 class MyFormSet(BaseFormSet):
     def __init__(self, useful_attribute, *args, **kwargs):
         self.useful_attribute = useful_attribute
         super().__init__(*args, **kwargs)

     def clean(self):
         super().clean()

         # validation code using self.useful_attribute...


 # usage in a view...

     the_formset = formset_factory(MyForm, formset=MyFormSet, extra=0)

     bound_formset = the_formset(initial=initial_results,
         form_kwargs=form_kwargs,
         formset_kwargs={"useful_attribute": useful_value})
 }}}

 The kwargs provided in formset_kwargs would then be passed to MyFormSet
 when it is instantiated.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35949>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019370ee8435-83d2c599-a8c8-41f3-946d-bfb19b445a53-000000%40eu-central-1.amazonses.com.

Reply via email to