summaryrefslogtreecommitdiff
path: root/tests/inline_formsets
diff options
context:
space:
mode:
Diffstat (limited to 'tests/inline_formsets')
-rw-r--r--tests/inline_formsets/models.py22
-rw-r--r--tests/inline_formsets/tests.py14
2 files changed, 35 insertions, 1 deletions
diff --git a/tests/inline_formsets/models.py b/tests/inline_formsets/models.py
index a090387c42..ccada27e4c 100644
--- a/tests/inline_formsets/models.py
+++ b/tests/inline_formsets/models.py
@@ -1,4 +1,5 @@
from django.db import models
+from django.db.models.functions import UUID4
class School(models.Model):
@@ -21,6 +22,27 @@ class Child(models.Model):
]
+class ParentUUIDPk(models.Model):
+ uuid = models.UUIDField(primary_key=True, db_default=UUID4(), editable=False)
+
+ class Meta:
+ required_db_features = {
+ "supports_uuid4_function",
+ "supports_expression_defaults",
+ }
+
+
+class ChildUUIDPk(models.Model):
+ parent = models.ForeignKey(ParentUUIDPk, models.CASCADE)
+ name = models.CharField(max_length=100)
+
+ class Meta:
+ required_db_features = {
+ "supports_uuid4_function",
+ "supports_expression_defaults",
+ }
+
+
class Poet(models.Model):
name = models.CharField(max_length=100)
diff --git a/tests/inline_formsets/tests.py b/tests/inline_formsets/tests.py
index eaabc350b4..78456ec514 100644
--- a/tests/inline_formsets/tests.py
+++ b/tests/inline_formsets/tests.py
@@ -1,7 +1,7 @@
from django.forms.models import ModelForm, inlineformset_factory
from django.test import TestCase, skipUnlessDBFeature
-from .models import Child, Parent, Poem, Poet, School
+from .models import Child, ChildUUIDPk, Parent, ParentUUIDPk, Poem, Poet, School
class DeletionTests(TestCase):
@@ -113,6 +113,18 @@ class DeletionTests(TestCase):
obj.save()
self.assertEqual(school.child_set.count(), 1)
+ @skipUnlessDBFeature("supports_uuid4_function", "supports_expression_defaults")
+ def test_add_form_uuid_pk(self):
+ ChildFormSet = inlineformset_factory(ParentUUIDPk, ChildUUIDPk, fields=["name"])
+ data = {
+ "child_set-TOTAL_FORMS": "1",
+ "child_set-INITIAL_FORMS": "1",
+ "child_set-MAX_NUM_FORMS": "0",
+ "child_set-0-name": "child",
+ }
+ formset = ChildFormSet(data)
+ self.assertIs(formset.is_valid(), False)
+
class InlineFormsetFactoryTest(TestCase):
def test_inline_formset_factory(self):