[Django] #35949: Add formset_kwargs keyword argument to BaseFormSet

6 views
Skip to first unread message

Django

unread,
Nov 27, 2024, 11:01:46 PM11/27/24
to django-...@googlegroups.com
#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.

Django

unread,
Nov 28, 2024, 2:21:51 AM11/28/24
to django-...@googlegroups.com
#35949: Add formset_kwargs keyword argument to BaseFormSet
------------------------------------+--------------------------------------
Reporter: Richard Brockie | Owner: (none)
Type: New feature | Status: closed
Component: Forms | Version: 5.1
Severity: Normal | Resolution: wontfix
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
------------------------------------+--------------------------------------
Changes (by Sarah Boyce):

* cc: David Smith (added)
* resolution: => wontfix
* status: new => closed

Comment:

Hi Richard, thank you for the ticket

For new feature requests, the recommended path forward is to first propose
and discuss the idea with the community and gain consensus. To do that,
please consider starting a new conversation on the
[https://forum.djangoproject.com/c/internals/5 Django Forum], where you'll
reach a broader audience and receive additional feedback.

I'll close the ticket for now, but if the community agrees with the
proposal, please return to this ticket and reference the forum discussion
so we can re-open it. For more information, please refer to
[https://docs.djangoproject.com/en/stable/internals/contributing/bugs-and-
features/#requesting-features the documented guidelines for requesting
features].
--
Ticket URL: <https://code.djangoproject.com/ticket/35949#comment:1>

Django

unread,
Nov 28, 2024, 11:54:34 AM11/28/24
to django-...@googlegroups.com
#35949: Add formset_kwargs keyword argument to BaseFormSet
------------------------------------+--------------------------------------
Reporter: Richard Brockie | Owner: (none)
Type: New feature | Status: closed
Component: Forms | Version: 5.1
Severity: Normal | Resolution: wontfix
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
------------------------------------+--------------------------------------
Comment (by Richard Brockie):

Hi Sarah,

Thanks for the pointers!
R.
--
Ticket URL: <https://code.djangoproject.com/ticket/35949#comment:2>

Django

unread,
Nov 29, 2024, 12:49:52 PM11/29/24
to django-...@googlegroups.com
#35949: Add formset_kwargs keyword argument to BaseFormSet
------------------------------------+--------------------------------------
Reporter: Richard Brockie | Owner: (none)
Type: New feature | Status: closed
Component: Forms | Version: 5.1
Severity: Normal | Resolution: wontfix
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
------------------------------------+--------------------------------------
Comment (by Richard Brockie):

Carlton Gibson sorted out my misunderstanding. Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/35949#comment:3>
Django <https://code.djangoproject.com/>
The web framework for perfectionists with deadlines.
Reply all
Reply to author
Forward
0 new messages