summaryrefslogtreecommitdiff
path: root/django/forms/formsets.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2020-10-26 00:02:38 -0700
committerGitHub <noreply@github.com>2020-10-26 08:02:38 +0100
commitb2717c7532cd35ab9e80c92c6b9f070e62e7ae88 (patch)
tree9ea04d937cd07a331ec0247e1b74b94f0d33489f /django/forms/formsets.py
parent2b56c566532c17dab4916a5a60e4db24a07eaa1a (diff)
Simplifed formset iteration using enumerate().
Diffstat (limited to 'django/forms/formsets.py')
-rw-r--r--django/forms/formsets.py12
1 files changed, 4 insertions, 8 deletions
diff --git a/django/forms/formsets.py b/django/forms/formsets.py
index 3f57399caf..606b659799 100644
--- a/django/forms/formsets.py
+++ b/django/forms/formsets.py
@@ -223,8 +223,7 @@ class BaseFormSet:
# that have had their deletion widget set to True
if not hasattr(self, '_deleted_form_indexes'):
self._deleted_form_indexes = []
- for i in range(0, self.total_form_count()):
- form = self.forms[i]
+ for i, form in enumerate(self.forms):
# if this is an extra form and hasn't changed, don't consider it
if i >= self.initial_form_count() and not form.has_changed():
continue
@@ -246,8 +245,7 @@ class BaseFormSet:
# by the form data.
if not hasattr(self, '_ordering'):
self._ordering = []
- for i in range(0, self.total_form_count()):
- form = self.forms[i]
+ for i, form in enumerate(self.forms):
# if this is an extra form and hasn't changed, don't consider it
if i >= self.initial_form_count() and not form.has_changed():
continue
@@ -313,8 +311,7 @@ class BaseFormSet:
forms_valid = True
# This triggers a full clean.
self.errors
- for i in range(0, self.total_form_count()):
- form = self.forms[i]
+ for form in self.forms:
if self.can_delete and self._should_delete_form(form):
# This form is going to be deleted so any of its errors
# shouldn't cause the entire formset to be invalid.
@@ -333,8 +330,7 @@ class BaseFormSet:
if not self.is_bound: # Stop further processing.
return
- for i in range(0, self.total_form_count()):
- form = self.forms[i]
+ for i, form in enumerate(self.forms):
# Empty forms are unchanged forms beyond those with initial data.
if not form.has_changed() and i >= self.initial_form_count():
empty_forms_count += 1