mirror of
https://github.com/django/django.git
synced 2025-01-18 14:24:39 +00:00
Improved formset docs by using a set instead of a list in the custom validation example.
This commit is contained in:
parent
76c3e310dd
commit
c59be9f1da
@ -374,14 +374,14 @@ is where you define your own validation that works at the formset level:
|
||||
... if any(self.errors):
|
||||
... # Don't bother validating the formset unless each form is valid on its own
|
||||
... return
|
||||
... titles = []
|
||||
... titles = set()
|
||||
... for form in self.forms:
|
||||
... if self.can_delete and self._should_delete_form(form):
|
||||
... continue
|
||||
... title = form.cleaned_data.get("title")
|
||||
... if title in titles:
|
||||
... raise ValidationError("Articles in a set must have distinct titles.")
|
||||
... titles.append(title)
|
||||
... titles.add(title)
|
||||
...
|
||||
|
||||
>>> ArticleFormSet = formset_factory(ArticleForm, formset=BaseArticleFormSet)
|
||||
|
Loading…
x
Reference in New Issue
Block a user