diff options
| author | Anssi Kääriäinen <akaariai@gmail.com> | 2013-08-20 17:13:41 +0300 |
|---|---|---|
| committer | Anssi Kääriäinen <akaariai@gmail.com> | 2013-08-21 08:32:19 +0300 |
| commit | b065aeb17f9daf395e22d4d5f9f49c0e2c7f4522 (patch) | |
| tree | fa2d63fddb5b8df8a4c4d0ac3e83974a96daee6e /tests | |
| parent | 83e434a2c2910d9e0540ea693d5f65e6550240c1 (diff) | |
Fixed #20946 -- model inheritance + m2m failure
Cleaned up the internal implementation of m2m fields by removing
related.py _get_fk_val(). The _get_fk_val() was doing the wrong thing
if asked for the foreign key value on foreign key to parent model's
primary key when child model had different primary key field.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/model_inheritance/models.py | 6 | ||||
| -rw-r--r-- | tests/model_inheritance/tests.py | 16 |
2 files changed, 21 insertions, 1 deletions
diff --git a/tests/model_inheritance/models.py b/tests/model_inheritance/models.py index 106645d23c..020bb35bc7 100644 --- a/tests/model_inheritance/models.py +++ b/tests/model_inheritance/models.py @@ -162,3 +162,9 @@ class Mixin(object): class MixinModel(models.Model, Mixin): pass + +class Base(models.Model): + titles = models.ManyToManyField(Title) + +class SubBase(Base): + sub_id = models.IntegerField(primary_key=True) diff --git a/tests/model_inheritance/tests.py b/tests/model_inheritance/tests.py index b8ab0c8581..dab3088a41 100644 --- a/tests/model_inheritance/tests.py +++ b/tests/model_inheritance/tests.py @@ -10,7 +10,8 @@ from django.utils import six from .models import ( Chef, CommonInfo, ItalianRestaurant, ParkingLot, Place, Post, - Restaurant, Student, StudentWorker, Supplier, Worker, MixinModel) + Restaurant, Student, StudentWorker, Supplier, Worker, MixinModel, + Title, Base, SubBase) class ModelInheritanceTests(TestCase): @@ -357,3 +358,16 @@ class ModelInheritanceTests(TestCase): [Place.objects.get(pk=s.pk)], lambda x: x ) + + def test_custompk_m2m(self): + b = Base.objects.create() + b.titles.add(Title.objects.create(title="foof")) + s = SubBase.objects.create(sub_id=b.id) + b = Base.objects.get(pk=s.id) + self.assertNotEqual(b.pk, s.pk) + # Low-level test for related_val + self.assertEqual(s.titles.related_val, (s.id,)) + # Higher level test for correct query values (title foof not + # accidentally found). + self.assertQuerysetEqual( + s.titles.all(), []) |
