Skip to content

Commit

Permalink
[4.2.x] Improved formset docs by using a set instead of a list in the…
Browse files Browse the repository at this point in the history
… custom validation example.

Backport of c59be9f from main
  • Loading branch information
lallulli authored and nessita committed Aug 24, 2023
1 parent f55b420 commit dcb9d7a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/topics/forms/formsets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,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)
Expand Down

0 comments on commit dcb9d7a

Please sign in to comment.