Code

Opened 11 months ago

Closed 9 months ago

Last modified 9 months ago

#21006 closed Cleanup/optimization (fixed)

Add an example of the formset argument for inlineformset_factory

Reported by: treysta@… Owned by: tianyi
Component: Documentation Version: 1.5
Severity: Normal Keywords: afraid-to-commit
Cc: treysta@…, EvilDMP 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 timo)

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)

Attachments (0)

Change History (12)

comment:1 Changed 11 months ago by timo

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Overriding clean() on an InlineFormSet to Add an example of the formset argument for inlineformset_factory
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Cleanup/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!

comment:2 Changed 10 months ago by EvilDMP

  • Cc EvilDMP added
  • Keywords afraid-to-commit added

comment:3 Changed 10 months ago by EvilDMP

I've marked this ticket as especially suitable for first-time committers or people following the Don't be afraid to commit tutorial. If you're tackling this ticket, please don't hesitate to ask me for guidance if you'd like any, either here or on the Django IRC channels, where I can be found as EvilDMP.

comment:4 Changed 9 months ago by tianyi

  • Owner changed from nobody to tianyi
  • Status changed from new to assigned

comment:6 Changed 9 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 9bfe66164e0e214abc6063a1a60ce729094d0632:

Fixed #21006 -- Added example code for overriding methods on an InlineFormSet.

Thanks treysta at gmail.com for the suggestion.

comment:7 Changed 9 months ago by Tim Graham <timograham@…>

In ecfd958c84a2b224ff1b71c42cfe481da98c14e6:

[1.6.x] Fixed #21006 -- Added example code for overriding methods on an InlineFormSet.

Thanks treysta at gmail.com for the suggestion.

Backport of 9bfe66164e from master

comment:8 Changed 9 months ago by Tim Graham <timograham@…>

In 1acd5fc9d293ac07adbb38d11c415dbadd431353:

[1.5.x] Fixed #21006 -- Added example code for overriding methods on an InlineFormSet.

Thanks treysta at gmail.com for the suggestion.

Backport of 9bfe66164e from master

comment:9 Changed 9 months ago by Tianyi Wang <wty52133@…>

In 944a2bb7c1ffdbf577c3b76acd76b7df7f7e11c0:

Improvement on InlineFormSet doc, refs #21006

comment:10 Changed 9 months ago by Daniele Procida <daniele@…>

In ec0e780e7ff2f6d4ac22fa8d41040e45b519e80e:

Merge pull request #1751 from tmaster/ticket_21006_improvement

Improvement on InlineFormSet doc, refs #21006

comment:11 Changed 9 months ago by Tim Graham <timograham@…>

In 312ca5e9cb89af790fa8af04811a3e4c5e621758:

[1.5.x] Improvement on InlineFormSet doc, refs #21006

Backport of 944a2bb7c1 from master

comment:12 Changed 9 months ago by Tim Graham <timograham@…>

In 1241a2cc104d092ff0f03a16a664e9e4ab801dd1:

[1.6.x] Improvement on InlineFormSet doc, refs #21006

Backport of 944a2bb7c1 from master

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.