summaryrefslogtreecommitdiff
path: root/tests/inline_formsets
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2016-03-24 20:04:25 -0400
committerSimon Charette <charette.s@gmail.com>2016-03-26 21:49:41 -0400
commit1a403aa705e7921eb6ec88c7d9f686ab0e54ef76 (patch)
tree0a4d0cdab524eed7386001bf82da1a325b311417 /tests/inline_formsets
parent2c125bded1834cadf3a6132d9ab87bc74f5ed728 (diff)
Fixed #25987 -- Made inline formset validation respect unique_together with an unsaved parent object.
Thanks Anton Kuzmichev for the report and Tim for the review.
Diffstat (limited to 'tests/inline_formsets')
-rw-r--r--tests/inline_formsets/models.py3
-rw-r--r--tests/inline_formsets/tests.py14
2 files changed, 17 insertions, 0 deletions
diff --git a/tests/inline_formsets/models.py b/tests/inline_formsets/models.py
index d94069d5db..70f9008d8b 100644
--- a/tests/inline_formsets/models.py
+++ b/tests/inline_formsets/models.py
@@ -31,5 +31,8 @@ class Poem(models.Model):
poet = models.ForeignKey(Poet, models.CASCADE)
name = models.CharField(max_length=100)
+ class Meta:
+ unique_together = ('poet', 'name')
+
def __str__(self):
return self.name
diff --git a/tests/inline_formsets/tests.py b/tests/inline_formsets/tests.py
index c298f9430e..f516ae8c7b 100644
--- a/tests/inline_formsets/tests.py
+++ b/tests/inline_formsets/tests.py
@@ -162,3 +162,17 @@ class InlineFormsetFactoryTest(TestCase):
PoemFormSet = inlineformset_factory(Poet, Poem, fields="__all__", extra=0)
formset = PoemFormSet(None, instance=poet)
self.assertEqual(len(formset.forms), 1)
+
+ def test_unsaved_fk_validate_unique(self):
+ poet = Poet(name='unsaved')
+ PoemFormSet = inlineformset_factory(Poet, Poem, fields=['name'])
+ data = {
+ 'poem_set-TOTAL_FORMS': '2',
+ 'poem_set-INITIAL_FORMS': '0',
+ 'poem_set-MAX_NUM_FORMS': '2',
+ 'poem_set-0-name': 'Poem',
+ 'poem_set-1-name': 'Poem',
+ }
+ formset = PoemFormSet(data, instance=poet)
+ self.assertFalse(formset.is_valid())
+ self.assertEqual(formset.non_form_errors(), ['Please correct the duplicate data for name.'])