#16995: ModelFormSet initial data from initial parameter uses "extra" forms -------------------------------+------------------------------------ Reporter: p910221@… | Owner: nobody Type: Bug | Status: new Component: Documentation | Version: SVN Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------+------------------------------------
Comment (by supervacuo): I was about to report this as a separate bug (after asking in `#django- dev`); I see this is as a feature proposal along the lines of "Set `extra` to the length of `initial` in !ModelFormSet if it is not set manually". I'm using `modelformset_factory` to create a model formset class, then passing `initial` in the constructor when instantiating it. Line 91 of `forms/formsets.py` uses the value of `extra` to work out how many `extra` forms should be drawn, but I think this information could already be implied by the length of the `initial` dict, at least in the case where `extra` is not specified (for backwards compatibility), and having to specify both seems a little like Repeating Yourself. The code I'm using which demonstrates the problem is [http://dpaste.org/QPWmn/ here]. I can certainly try writing a patch (it shouldn't be a big change, and I imagine the tests would be pretty straightforward) if this seems like a good idea. If not, I agree that the "Making forms from models" docs should explain that `extra` needs to be set, even with `initial`, using something like {{{ from django.forms.models import modelformset_factory foos = some_function_that_returns_a_list_of_foo() FooFormSet = modelformset_factory(Foo, extra=len(foos)) foo_formset = FooFormSet(initial=[f.__dict__ for f in foos]) }}} -- Ticket URL: <https://code.djangoproject.com/ticket/16995#comment:2> 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 post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.