summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2009-03-09 03:35:02 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2009-03-09 03:35:02 +0000
commitb4dd4d4bb7db6533e13be1455ccdc52c3d50cac3 (patch)
tree8db98c18415f071584c8f59369872f4fb6b35925 /django/db
parent98710a5a2853594f5bad161f9a3bedd27171bb89 (diff)
Fixed #3163 -- Add a "Meta.managed" option to models.
This allows a model to be defined which is not subject to database table creation and removal. Useful for models that sit over existing tables or database views. Thanks to Alexander Myodov, Wolfgang Kriesing and Ryan Kelly for the bulk of this patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10008 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db')
-rw-r--r--django/db/backends/__init__.py4
-rw-r--r--django/db/backends/creation.py10
-rw-r--r--django/db/models/options.py3
3 files changed, 16 insertions, 1 deletions
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
index 6b027de193..5a3cb53842 100644
--- a/django/db/backends/__init__.py
+++ b/django/db/backends/__init__.py
@@ -450,6 +450,8 @@ class BaseDatabaseIntrospection(object):
tables = set()
for app in models.get_apps():
for model in models.get_models(app):
+ if not model._meta.managed:
+ continue
tables.add(model._meta.db_table)
tables.update([f.m2m_db_table() for f in model._meta.local_many_to_many])
if only_existing:
@@ -476,6 +478,8 @@ class BaseDatabaseIntrospection(object):
for app in apps:
for model in models.get_models(app):
+ if not model._meta.managed:
+ continue
for f in model._meta.local_fields:
if isinstance(f, models.AutoField):
sequence_list.append({'table': model._meta.db_table, 'column': f.column})
diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py
index e6399874ef..9bebce9065 100644
--- a/django/db/backends/creation.py
+++ b/django/db/backends/creation.py
@@ -33,6 +33,8 @@ class BaseDatabaseCreation(object):
from django.db import models
opts = model._meta
+ if not opts.managed:
+ return [], {}
final_output = []
table_output = []
pending_references = {}
@@ -112,6 +114,8 @@ class BaseDatabaseCreation(object):
"Returns any ALTER TABLE statements to add constraints after the fact."
from django.db.backends.util import truncate_name
+ if not model._meta.managed:
+ return []
qn = self.connection.ops.quote_name
final_output = []
opts = model._meta
@@ -225,6 +229,8 @@ class BaseDatabaseCreation(object):
def sql_indexes_for_model(self, model, style):
"Returns the CREATE INDEX SQL statements for a single model"
+ if not model._meta.managed:
+ return []
output = []
for f in model._meta.local_fields:
output.extend(self.sql_indexes_for_field(model, f, style))
@@ -255,6 +261,8 @@ class BaseDatabaseCreation(object):
def sql_destroy_model(self, model, references_to_delete, style):
"Return the DROP TABLE and restraint dropping statements for a single model"
+ if not model._meta.managed:
+ return []
# Drop the table now
qn = self.connection.ops.quote_name
output = ['%s %s;' % (style.SQL_KEYWORD('DROP TABLE'),
@@ -271,6 +279,8 @@ class BaseDatabaseCreation(object):
def sql_remove_table_constraints(self, model, references_to_delete, style):
from django.db.backends.util import truncate_name
+ if not model._meta.managed:
+ return []
output = []
qn = self.connection.ops.quote_name
for rel_class, f in references_to_delete[model]:
diff --git a/django/db/models/options.py b/django/db/models/options.py
index 06e17c61ad..2dd3d256a1 100644
--- a/django/db/models/options.py
+++ b/django/db/models/options.py
@@ -21,7 +21,7 @@ get_verbose_name = lambda class_name: re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|
DEFAULT_NAMES = ('verbose_name', 'db_table', 'ordering',
'unique_together', 'permissions', 'get_latest_by',
'order_with_respect_to', 'app_label', 'db_tablespace',
- 'abstract')
+ 'abstract', 'managed')
class Options(object):
def __init__(self, meta, app_label=None):
@@ -42,6 +42,7 @@ class Options(object):
self.pk = None
self.has_auto_field, self.auto_field = False, None
self.abstract = False
+ self.managed = True
self.parents = SortedDict()
self.duplicate_targets = {}
# Managers that have been inherited from abstract base classes. These