#14009: custom formset validation documentation is incomplete
--------------------------------------------+-------------------------------
Reporter: splatEric <[email protected]> | Owner: nobody
Status: new | Milestone:
Component: Documentation | Version: 1.2
Keywords: formset validation | Stage: Unreviewed
Has_patch: 1 |
--------------------------------------------+-------------------------------
The example for performing custom formset validation is incomplete. It
does not take into account deleted forms, or empty forms for checking the
unique titles constraint. It should read something along the lines of
(changes highlighted by *>):
{{{
>>> class BaseArticleFormSet(BaseFormSet):
... def clean(self):
... """Checks that no two articles have the same title."""
... if any(self.errors):
... # Don't bother validating the formset unless each form is
valid on its own
... return
... titles = []
... for i in range(0, self.total_form_count()):
*> if self.can_delete and self._should_delete_form(form):
*> continue
... form = self.forms[i]
*> if 'title' in form.cleaned_data:
... title = form.cleaned_data['title']
... if title in titles:
... raise forms.ValidationError, "Articles in a set
must have distinct titles."
... titles.append(title)
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/14009>
Django <http://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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.