mirror of
https://github.com/django/django.git
synced 2025-01-18 06:12:23 +00:00
Fixed #26304 -- Ignored unmanaged through model in table introspection.
This commit is contained in:
parent
5155c2b458
commit
60633ef3de
1
AUTHORS
1
AUTHORS
@ -481,6 +481,7 @@ answer newbie questions, and generally made Django that much better:
|
|||||||
Matt Deacalion Stevens <matt@dirtymonkey.co.uk>
|
Matt Deacalion Stevens <matt@dirtymonkey.co.uk>
|
||||||
Matt Dennenbaum
|
Matt Dennenbaum
|
||||||
Matthew Flanagan <http://wadofstuff.blogspot.com>
|
Matthew Flanagan <http://wadofstuff.blogspot.com>
|
||||||
|
Matthew Schinckel <matt@schinckel.net>
|
||||||
Matthew Somerville <matthew-django@dracos.co.uk>
|
Matthew Somerville <matthew-django@dracos.co.uk>
|
||||||
Matthew Tretter <m@tthewwithanm.com>
|
Matthew Tretter <m@tthewwithanm.com>
|
||||||
Matthias Kestenholz <mk@406.ch>
|
Matthias Kestenholz <mk@406.ch>
|
||||||
|
@ -80,7 +80,10 @@ class BaseDatabaseIntrospection(object):
|
|||||||
if not model._meta.managed:
|
if not model._meta.managed:
|
||||||
continue
|
continue
|
||||||
tables.add(model._meta.db_table)
|
tables.add(model._meta.db_table)
|
||||||
tables.update(f.m2m_db_table() for f in model._meta.local_many_to_many)
|
tables.update(
|
||||||
|
f.m2m_db_table() for f in model._meta.local_many_to_many
|
||||||
|
if f.remote_field.through._meta.managed
|
||||||
|
)
|
||||||
tables = list(tables)
|
tables = list(tables)
|
||||||
if only_existing:
|
if only_existing:
|
||||||
existing_tables = self.table_names(include_views=include_views)
|
existing_tables = self.table_names(include_views=include_views)
|
||||||
|
@ -45,6 +45,7 @@ class Article(models.Model):
|
|||||||
body = models.TextField(default='')
|
body = models.TextField(default='')
|
||||||
reporter = models.ForeignKey(Reporter, models.CASCADE)
|
reporter = models.ForeignKey(Reporter, models.CASCADE)
|
||||||
response_to = models.ForeignKey('self', models.SET_NULL, null=True)
|
response_to = models.ForeignKey('self', models.SET_NULL, null=True)
|
||||||
|
unmanaged_reporters = models.ManyToManyField(Reporter, through='ArticleReporter')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.headline
|
return self.headline
|
||||||
@ -54,3 +55,11 @@ class Article(models.Model):
|
|||||||
index_together = [
|
index_together = [
|
||||||
["headline", "pub_date"],
|
["headline", "pub_date"],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ArticleReporter(models.Model):
|
||||||
|
article = models.ForeignKey(Article, models.CASCADE)
|
||||||
|
reporter = models.ForeignKey(Reporter, models.CASCADE)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
managed = False
|
||||||
|
@ -6,7 +6,7 @@ from django.db import connection
|
|||||||
from django.db.utils import DatabaseError
|
from django.db.utils import DatabaseError
|
||||||
from django.test import TransactionTestCase, mock, skipUnlessDBFeature
|
from django.test import TransactionTestCase, mock, skipUnlessDBFeature
|
||||||
|
|
||||||
from .models import Article, City, Reporter
|
from .models import Article, ArticleReporter, City, Reporter
|
||||||
|
|
||||||
|
|
||||||
class IntrospectionTests(TransactionTestCase):
|
class IntrospectionTests(TransactionTestCase):
|
||||||
@ -53,6 +53,10 @@ class IntrospectionTests(TransactionTestCase):
|
|||||||
self.assertNotIn('introspection_article_view',
|
self.assertNotIn('introspection_article_view',
|
||||||
connection.introspection.table_names())
|
connection.introspection.table_names())
|
||||||
|
|
||||||
|
def test_unmanaged_through_model(self):
|
||||||
|
tables = connection.introspection.django_table_names()
|
||||||
|
self.assertNotIn(ArticleReporter._meta.db_table, tables)
|
||||||
|
|
||||||
def test_installed_models(self):
|
def test_installed_models(self):
|
||||||
tables = [Article._meta.db_table, Reporter._meta.db_table]
|
tables = [Article._meta.db_table, Reporter._meta.db_table]
|
||||||
models = connection.introspection.installed_models(tables)
|
models = connection.introspection.installed_models(tables)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user