summaryrefslogtreecommitdiff
path: root/django/forms/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/forms/models.py')
-rw-r--r--django/forms/models.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/django/forms/models.py b/django/forms/models.py
index d0bdbde0b6..3cafdebd34 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -564,6 +564,9 @@ class BaseModelFormSet(BaseFormSet):
"""
model = None
+ # Set of fields that must be unique among forms of this set.
+ unique_fields = set()
+
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
queryset=None, **kwargs):
self.queryset = queryset
@@ -677,9 +680,11 @@ class BaseModelFormSet(BaseFormSet):
for uclass, unique_check in all_unique_checks:
seen_data = set()
for form in valid_forms:
- # get data for each field of each of unique_check
- row_data = (form.cleaned_data[field]
- for field in unique_check if field in form.cleaned_data)
+ # Get the data for the set of fields that must be unique among the forms.
+ row_data = (
+ field if field in self.unique_fields else form.cleaned_data[field]
+ for field in unique_check if field in form.cleaned_data
+ )
# Reduce Model instances to their primary key values
row_data = tuple(d._get_pk_val() if hasattr(d, '_get_pk_val') else d
for d in row_data)
@@ -878,6 +883,7 @@ class BaseInlineFormSet(BaseModelFormSet):
qs = queryset.filter(**{self.fk.name: self.instance})
else:
qs = queryset.none()
+ self.unique_fields = {self.fk.name}
super(BaseInlineFormSet, self).__init__(data, files, prefix=prefix,
queryset=qs, **kwargs)