mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
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 '+'.
This commit is contained in:
parent
14f28f8233
commit
4ee08958f1
5 changed files with 40 additions and 12 deletions
|
@ -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>'])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue