summaryrefslogtreecommitdiff
path: root/tests/model_formsets/test_uuid.py
diff options
context:
space:
mode:
authorNeeraj Kumar <sainineeraj1234@gmail.com>2023-06-07 01:27:32 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-07-07 09:11:46 +0200
commiteed096574fea5c9d82d0dc5952ad439dfde13718 (patch)
treee61a70657c124e06da5a71c0dca6f648aa04c3e4 /tests/model_formsets/test_uuid.py
parentb91d62cca07638741f5902713983f71478589b0e (diff)
Fixed #32210 -- Fixed model inlines with to_field that has a default.
Diffstat (limited to 'tests/model_formsets/test_uuid.py')
-rw-r--r--tests/model_formsets/test_uuid.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/model_formsets/test_uuid.py b/tests/model_formsets/test_uuid.py
index 2084fc2987..0a2d504c84 100644
--- a/tests/model_formsets/test_uuid.py
+++ b/tests/model_formsets/test_uuid.py
@@ -93,3 +93,25 @@ class InlineFormsetTests(TestCase):
)
formset = FormSet()
self.assertIsNone(formset.forms[0].fields["parent"].initial)
+
+ def test_inlineformset_factory_nulls_default_pks_alternate_key_relation_data(self):
+ """
+ If form data is provided, a parent's auto-generated alternate key is
+ set.
+ """
+ FormSet = inlineformset_factory(
+ ParentWithUUIDAlternateKey, ChildRelatedViaAK, fields="__all__"
+ )
+ formset = FormSet(
+ {
+ "childrelatedviaak_set-TOTAL_FORMS": 3,
+ "childrelatedviaak_set-INITIAL_FORMS": 0,
+ "childrelatedviaak_set-MAX_NUM_FORMS": "",
+ "childrelatedviaak_set-0-name": "Test",
+ "childrelatedviaak_set-1-name": "",
+ "childrelatedviaak_set-2-name": "",
+ }
+ )
+ self.assertIs(formset.is_valid(), True)
+ self.assertIsNotNone(formset.instance.uuid)
+ self.assertEqual(formset.forms[0].instance.parent_id, formset.instance.uuid)