1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Improved formset docs by using a set instead of a list in the custom validation example.

This commit is contained in:
Luca Allulli
2023-08-24 03:24:43 +02:00
committed by GitHub
parent 76c3e310dd
commit c59be9f1da

View File

@@ -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)