From dcb9d7a0e4b29a34c88969ab3fac8c345224c43b Mon Sep 17 00:00:00 2001 From: Luca Allulli Date: Thu, 24 Aug 2023 03:24:43 +0200 Subject: [PATCH] [4.2.x] Improved formset docs by using a set instead of a list in the custom validation example. Backport of c59be9f1da7e1fc58df49d5eda4e80cd50ce5710 from main --- docs/topics/forms/formsets.txt | 4 ++-- 1 file 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)