#10287 closed (fixed)
Formset documentation has no information about practical formset validation
Reported by: | aidan | Owned by: | Andrew Badr |
---|---|---|---|
Component: | Documentation | Version: | 1.0 |
Severity: | Keywords: | docs, formsets | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Although the clean method is demonstrated, no actual validation is demonstrated.
It is unclear whether self.forms should be iterated and cleaned_data examined - a property which may or may not exist.
Attachments (1)
Change History (9)
comment:1 by , 16 years ago
milestone: | → 1.1 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 15 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
by , 15 years ago
Attachment: | formset-docs.diff added |
---|
comment:4 by , 15 years ago
Has patch: | set |
---|
comment:5 by , 15 years ago
Also, this is my first documentation patch. Did my changes overstep the bounds of the ticket by too much? I'm worried that the first validation example is now a little clunky. Critique is welcome.
comment:6 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
(In 11234] Fixed #10287 -- Added better examples in the docs of formset validation. Thanks to Andrew Badr for the text.
comment:7 by , 15 years ago
Note:
See TracTickets
for help on using tickets.
This patch adds a more realistic example to the formset-level
clean
method. It also expands the first example in the "Formset validation" section so that it matches the later example, and to better explain the contents offormset.errors
.Like several methods in the internal formset code, the example
clean
in this patch iterates only through the firstself.total_form_count()
entries inself.forms
. This seems to be safer than iteratingself.forms
directly, because we may not use all the initial forms, or we may try to use more thanmax_num
. If I'm wrong about this, the exampleclean
should be changed to simply iterate throughself.forms
directly. That's what some other methods do, and I'm not confident that I understand the difference.Also, my
clean
method accesses the forms'cleaned_data
manually instead of using the formset'sself.cleaned_data
. This is mainly because of a comment onself.cleaned_data
saying "Maybe this should just go away?", but also becauseself.cleaned_data
iterates throughself.forms
, which I'm confused about (see above). If this is changed, the guard checkingany(self.errors)
must be kept, or else users accessingself.cleaned_data
with form-level validation errors will get an uncaught exception.