0
0
mirror of https://github.com/django/django.git synced 2024-11-28 21:43:13 +01:00

Fixed #27651 -- Allowed M2M to concrete and proxy through model.

This commit is contained in:
Tim Graham 2016-12-28 11:44:26 -05:00
parent aaecf038ca
commit e3e80da7a5
2 changed files with 22 additions and 2 deletions

View File

@ -1447,8 +1447,10 @@ class ManyToManyField(RelatedField):
if model != self.remote_field.through and model._meta.managed
}
m2m_db_table = self.m2m_db_table()
if m2m_db_table in registered_tables:
model = registered_tables[m2m_db_table]
model = registered_tables.get(m2m_db_table)
# The second condition allows multiple m2m relations on a model if
# some point to a through model that proxies another through model.
if model and model._meta.concrete_model != self.remote_field.through._meta.concrete_model:
if model._meta.auto_created:
def _get_field_name(model):
for field in model._meta.auto_created._meta.many_to_many:

View File

@ -899,6 +899,24 @@ class OtherModelTests(SimpleTestCase):
self.assertEqual(C1.check(), [])
self.assertEqual(C2.check(), [])
def test_m2m_to_concrete_and_proxy_allowed(self):
class A(models.Model):
pass
class Through(models.Model):
a = models.ForeignKey('A', models.CASCADE)
c = models.ForeignKey('C', models.CASCADE)
class ThroughProxy(Through):
class Meta:
proxy = True
class C(models.Model):
mm_a = models.ManyToManyField(A, through=Through)
mm_aproxy = models.ManyToManyField(A, through=ThroughProxy, related_name='proxied_m2m')
self.assertEqual(C.check(), [])
@isolate_apps('django.contrib.auth', kwarg_name='apps')
def test_lazy_reference_checks(self, apps):
class DummyModel(models.Model):