diff options
| author | Claude Paroz <claude@2xlibre.net> | 2014-09-21 00:00:52 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2014-09-23 20:13:31 +0200 |
| commit | ed297061a676e629983664031d77da1d0a70af7d (patch) | |
| tree | 963e7499189d929980284139fe9c9b13d717afe7 /django/db/backends/__init__.py | |
| parent | b8cdc7dcc3fc6897fb2a75f90023f5c67aad327f (diff) | |
Fixed #18782 -- Prevented sql_flush to flush views
Thanks rodolfo_3 for the report and the initial patch, and
Josh Smeaton, Shai Berger and Tim Graham for the reviews.
Diffstat (limited to 'django/db/backends/__init__.py')
| -rw-r--r-- | django/db/backends/__init__.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index 3420cadc47..1f0e7b255c 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -1274,17 +1274,20 @@ class BaseDatabaseIntrospection(object): """ return self.table_name_converter(name) - def table_names(self, cursor=None): + def table_names(self, cursor=None, include_views=False): """ Returns a list of names of all tables that exist in the database. The returned table list is sorted by Python's default sorting. We do NOT use database's ORDER BY here to avoid subtle differences in sorting order between databases. """ + def get_names(cursor): + return sorted([ti.name for ti in self.get_table_list(cursor) + if include_views or ti.type == 't']) if cursor is None: with self.connection.cursor() as cursor: - return sorted([ti.name for ti in self.get_table_list(cursor) if ti.type == 't']) - return sorted([ti.name for ti in self.get_table_list(cursor) if ti.type == 't']) + return get_names(cursor) + return get_names(cursor) def get_table_list(self, cursor): """ @@ -1293,7 +1296,7 @@ class BaseDatabaseIntrospection(object): """ raise NotImplementedError('subclasses of BaseDatabaseIntrospection may require a get_table_list() method') - def django_table_names(self, only_existing=False): + def django_table_names(self, only_existing=False, include_views=True): """ Returns a list of all table names that have associated Django models and are in INSTALLED_APPS. @@ -1312,7 +1315,7 @@ class BaseDatabaseIntrospection(object): tables.update(f.m2m_db_table() for f in model._meta.local_many_to_many) tables = list(tables) if only_existing: - existing_tables = self.table_names() + existing_tables = self.table_names(include_views=include_views) tables = [ t for t in tables |
