Browse Source

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

Luca Allulli 1 year ago
parent
commit
c59be9f1da
1 changed files with 2 additions and 2 deletions
  1. 2 2
      docs/topics/forms/formsets.txt

+ 2 - 2
docs/topics/forms/formsets.txt

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