Opened 11 years ago

Last modified 11 years ago

#21006 closed Cleanup/optimization

Add an example of the formset argument for inlineformset_factory — at Version 1

Reported by: treysta@… Owned by: nobody
Component: Documentation Version: 1.5
Severity: Normal Keywords: afraid-to-commit
Cc: treysta@…, Daniele Procida Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

https://docs.djangoproject.com/en/1.5/topics/forms/modelforms/#overriding-clean-on-an-inlineformset

It looks like there is a somewhat relevant piece of information missing from this section. It leaves out the fact that you also must specify which formset to use when creating your inlineformset in the view:

Currently:

"See Overriding clean() on a ModelFormSet, but subclass BaseInlineFormSet rather than BaseModelFormSet."

Suggestion:

"See Overriding clean() on a ModelFormSet, but subclass BaseInlineFormSet rather than BaseModelFormSet. You must also specify which formset to use when creating your inlineformset in your view:"

>>> from django.forms.models import inlineformset_factory
>>> BookFormSet = inlineformset_factory(Author, Book, formset= MyInlineFormSet)
>>> author = Author.objects.get(name=u'Mike Royko')
>>> formset = BookFormSet(instance=author)

Change History (1)

comment:1 by Tim Graham, 11 years ago

Description: modified (diff)
Summary: Overriding clean() on an InlineFormSetAdd an example of the formset argument for inlineformset_factory
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

There's an example for modelformset_factory that uses the formset argument and while you might be able to infer a similar technique will work for inlineformset_factory since the docs say "Inline formsets is a small abstraction layer on top of model formsets", I agree an example could be helpful. I'm not sure it should be specific to the "Overriding clean()" section though, since the formset argument is useful for other cases as well.

If you could offer a patch, I'll be happy to review and commit it. Thanks!

Note: See TracTickets for help on using tickets.
Back to Top