diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-11-02 12:30:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-02 12:30:16 +0100 |
commit | 57c2e5da710b583110d8c7c20e91774a61d7472f (patch) | |
tree | ca9dc0f7aa30b0fb7c4b75dcb37a82ae2a96c8e0 /tests/model_inheritance | |
parent | d5bcdf858d962d02de925603c17986980f03729a (diff) | |
download | django-57c2e5da710b583110d8c7c20e91774a61d7472f.tar.gz |
Refs #33984 -- Added test for creating copies of model instances with inherited m2m fields.
Diffstat (limited to 'tests/model_inheritance')
-rw-r--r-- | tests/model_inheritance/models.py | 4 | ||||
-rw-r--r-- | tests/model_inheritance/tests.py | 17 |
2 files changed, 21 insertions, 0 deletions
diff --git a/tests/model_inheritance/models.py b/tests/model_inheritance/models.py index a479faeda5..dc0e238f7e 100644 --- a/tests/model_inheritance/models.py +++ b/tests/model_inheritance/models.py @@ -110,6 +110,10 @@ class Supplier(Place): customers = models.ManyToManyField(Restaurant, related_name="provider") +class CustomSupplier(Supplier): + pass + + class ParkingLot(Place): # An explicit link to the parent (we can control the attribute name). parent = models.OneToOneField( diff --git a/tests/model_inheritance/tests.py b/tests/model_inheritance/tests.py index d53a4f3257..4542e6c3cc 100644 --- a/tests/model_inheritance/tests.py +++ b/tests/model_inheritance/tests.py @@ -10,6 +10,7 @@ from .models import ( Base, Chef, CommonInfo, + CustomSupplier, GrandChild, GrandParent, ItalianRestaurant, @@ -191,6 +192,22 @@ class ModelInheritanceTests(TestCase): sql = query["sql"] self.assertIn("INSERT INTO", sql, sql) + def test_create_copy_with_inherited_m2m(self): + restaurant = Restaurant.objects.create() + supplier = CustomSupplier.objects.create( + name="Central market", address="944 W. Fullerton" + ) + supplier.customers.set([restaurant]) + old_customers = supplier.customers.all() + supplier.pk = None + supplier.id = None + supplier._state.adding = True + supplier.save() + supplier.customers.set(old_customers) + supplier = Supplier.objects.get(pk=supplier.pk) + self.assertCountEqual(supplier.customers.all(), old_customers) + self.assertSequenceEqual(supplier.customers.all(), [restaurant]) + def test_eq(self): # Equality doesn't transfer in multitable inheritance. self.assertNotEqual(Place(id=1), Restaurant(id=1)) |