diff options
| author | Luca Allulli <l.allulli@gmail.com> | 2023-08-24 03:24:43 +0200 |
|---|---|---|
| committer | Natalia <124304+nessita@users.noreply.github.com> | 2023-08-23 22:26:05 -0300 |
| commit | dcb9d7a0e4b29a34c88969ab3fac8c345224c43b (patch) | |
| tree | 5c9781acbc195ec761773db32dad15f34fa26d7b | |
| parent | f55b420277083f2224fe5ef82ccdea66debaa3f3 (diff) | |
[4.2.x] Improved formset docs by using a set instead of a list in the custom validation example.
Backport of c59be9f1da7e1fc58df49d5eda4e80cd50ce5710 from main
| -rw-r--r-- | docs/topics/forms/formsets.txt | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/docs/topics/forms/formsets.txt b/docs/topics/forms/formsets.txt index 85ede62949..05cd69937d 100644 --- a/docs/topics/forms/formsets.txt +++ b/docs/topics/forms/formsets.txt @@ -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) |
