mirror of https://github.com/django/django.git
Refs #33984 -- Added test for creating copies of model instances with inherited m2m fields.
This commit is contained in:
parent
d5bcdf858d
commit
57c2e5da71
|
@ -110,6 +110,10 @@ class Supplier(Place):
|
||||||
customers = models.ManyToManyField(Restaurant, related_name="provider")
|
customers = models.ManyToManyField(Restaurant, related_name="provider")
|
||||||
|
|
||||||
|
|
||||||
|
class CustomSupplier(Supplier):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ParkingLot(Place):
|
class ParkingLot(Place):
|
||||||
# An explicit link to the parent (we can control the attribute name).
|
# An explicit link to the parent (we can control the attribute name).
|
||||||
parent = models.OneToOneField(
|
parent = models.OneToOneField(
|
||||||
|
|
|
@ -10,6 +10,7 @@ from .models import (
|
||||||
Base,
|
Base,
|
||||||
Chef,
|
Chef,
|
||||||
CommonInfo,
|
CommonInfo,
|
||||||
|
CustomSupplier,
|
||||||
GrandChild,
|
GrandChild,
|
||||||
GrandParent,
|
GrandParent,
|
||||||
ItalianRestaurant,
|
ItalianRestaurant,
|
||||||
|
@ -191,6 +192,22 @@ class ModelInheritanceTests(TestCase):
|
||||||
sql = query["sql"]
|
sql = query["sql"]
|
||||||
self.assertIn("INSERT INTO", sql, 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):
|
def test_eq(self):
|
||||||
# Equality doesn't transfer in multitable inheritance.
|
# Equality doesn't transfer in multitable inheritance.
|
||||||
self.assertNotEqual(Place(id=1), Restaurant(id=1))
|
self.assertNotEqual(Place(id=1), Restaurant(id=1))
|
||||||
|
|
Loading…
Reference in New Issue