1
0
mirror of https://github.com/django/django.git synced 2025-10-26 15:16:09 +00:00

[1.8.x] 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 '+'.

Backport of 4ee08958f1 from master
This commit is contained in:
Marco Fucci
2015-03-26 18:47:07 +00:00
committed by Tim Graham
parent 07e594bba2
commit 0e2d3b9304
6 changed files with 44 additions and 12 deletions

View File

@@ -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>'])