Opened 12 years ago
Closed 12 years ago
#20996 closed Uncategorized (invalid)
formset factories override any supplied formset max_num
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Forms | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Because of the way formset_factory yields a new object based on a given formset argument, during which it manually sets some attrs on the resulting object, it is impossible for the following to work:
class MyFormset(BaseFormSet):
def _max_num(self):
return 9000 # or whatever
max_num = property(_max_num)
FromFactory = formset_factory(MyForm, formset=MyFormset)
FromFactory.max_num # will be 1000
FromFactory.max_num = FromFactory._max_num()
FromFactory.max_num # will be 9000
It seems inconsiderate for the factory to override the max_num regardless of what the FormSet says is ok, silently.
I've left it uncategorized, because I can see the argument for the way it behaves currently [especially WRT backwards compatibility], but if it's not fixed, it may be worth finding a place in the documentation [docstrings and/or real docs] to indicate the behaviour.
Hi Keryn,
I've been searching the docs looking for a reference of a max_num attribute in formsets and I didn't find it, so it might be an internal attribute.
I did find some documentation on how to change the max_num for a formset using formset_factory, so at least that way of doing things is documented. https://docs.djangoproject.com/en/dev/topics/forms/formsets/#limiting-the-maximum-number-of-forms
This is the code that handles the max_num setting https://github.com/django/django/blob/aae5a96d5754ad34e48b7f673ef2411a3bbc1015/django/forms/formsets.py#L397
I'm going to set this as invalid given that there is documentation regarding how to change max_num and setting a max_num directly seems to be dealing with an internal API.
But please, if you consider that honoring the formset max_num attribute is an API worth having, reopen this ticket to discuss it a little better. And if you could provide a patch for that feature that would be awesome too.
Cheers!