diff options
| author | Marco Fucci <marcofucci@gmail.com> | 2015-03-26 18:47:07 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-03-26 19:00:37 -0400 |
| commit | 4ee08958f154594b538207a53c1d457687b3f7ae (patch) | |
| tree | 55b93347e4fa9d84f8773614169594d6b5221e4a /tests/m2m_regress | |
| parent | 14f28f82330b3d2ed7f16fa5de1596e50f2a3952 (diff) | |
Fixed #24505 -- Fixed clash with hidden m2m fields.
Added support for multiple m2m fields with the same 'to' model
and with related_name set to '+'.
Diffstat (limited to 'tests/m2m_regress')
| -rw-r--r-- | tests/m2m_regress/models.py | 11 | ||||
| -rw-r--r-- | tests/m2m_regress/tests.py | 13 |
2 files changed, 23 insertions, 1 deletions
diff --git a/tests/m2m_regress/models.py b/tests/m2m_regress/models.py index 4c1538dcbf..57f02b8f90 100644 --- a/tests/m2m_regress/models.py +++ b/tests/m2m_regress/models.py @@ -54,9 +54,13 @@ class SelfReferChildSibling(SelfRefer): # Many-to-Many relation between models, where one of the PK's isn't an Autofield +@python_2_unicode_compatible class Line(models.Model): name = models.CharField(max_length=100) + def __str__(self): + return self.name + class Worksheet(models.Model): id = models.CharField(primary_key=True, max_length=100) @@ -87,3 +91,10 @@ class RegressionModelSplit(BadModelWithSplit): Model with a split method should not cause an error in add_lazy_relation """ others = models.ManyToManyField('self') + + +# Regression for #24505 -- Two ManyToManyFields with the same "to" model +# and related_name set to '+'. +class Post(models.Model): + primary_lines = models.ManyToManyField(Line, related_name='+') + secondary_lines = models.ManyToManyField(Line, related_name='+') diff --git a/tests/m2m_regress/tests.py b/tests/m2m_regress/tests.py index 885efa593f..5e2891b0b4 100644 --- a/tests/m2m_regress/tests.py +++ b/tests/m2m_regress/tests.py @@ -5,7 +5,7 @@ from django.test import TestCase from django.utils import six from .models import ( - Entry, RegressionModelSplit, SelfRefer, SelfReferChild, + Entry, Line, Post, RegressionModelSplit, SelfRefer, SelfReferChild, SelfReferChildSibling, Tag, TagCollection, Worksheet, ) @@ -111,3 +111,14 @@ class M2MRegressionTests(TestCase): c1.refresh_from_db() self.assertQuerysetEqual(c1.tags.order_by('name'), ["<Tag: t1>", "<Tag: t2>"]) + + def test_multiple_forwards_only_m2m(self): + # Regression for #24505 - Multiple ManyToManyFields to same "to" + # model with related_name set to '+'. + foo = Line.objects.create(name='foo') + bar = Line.objects.create(name='bar') + post = Post.objects.create() + post.primary_lines.add(foo) + post.secondary_lines.add(bar) + self.assertQuerysetEqual(post.primary_lines.all(), ['<Line: foo>']) + self.assertQuerysetEqual(post.secondary_lines.all(), ['<Line: bar>']) |
