mirror of
https://github.com/django/django.git
synced 2025-10-26 07:06:08 +00:00
Small code cleanup -- changed django.core.management.get_sql_delete to use get_m2m_db_table(), and moved get_m2m_db_table() from Field to ManyToManyField, because it's only used by the latter
git-svn-id: http://code.djangoproject.com/svn/django/trunk@256 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -91,7 +91,7 @@ def get_sql_create(mod):
|
||||
for klass in mod._MODELS:
|
||||
opts = klass._meta
|
||||
for f in opts.many_to_many:
|
||||
table_output = ['CREATE TABLE %s_%s (' % (opts.db_table, f.name)]
|
||||
table_output = ['CREATE TABLE %s (' % f.get_m2m_db_table(opts)]
|
||||
table_output.append(' id %s NOT NULL PRIMARY KEY,' % db.DATA_TYPES['AutoField'])
|
||||
table_output.append(' %s_id %s NOT NULL REFERENCES %s (%s),' % \
|
||||
(opts.object_name.lower(), db.DATA_TYPES['IntegerField'], opts.db_table, opts.pk.name))
|
||||
@@ -127,11 +127,11 @@ def get_sql_delete(mod):
|
||||
for f in opts.many_to_many:
|
||||
try:
|
||||
if cursor is not None:
|
||||
cursor.execute("SELECT 1 FROM %s_%s LIMIT 1" % (opts.db_table, f.name))
|
||||
cursor.execute("SELECT 1 FROM %s LIMIT 1" % f.get_m2m_db_table(opts))
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
output.append("DROP TABLE %s_%s;" % (opts.db_table, f.name))
|
||||
output.append("DROP TABLE %s;" % f.get_m2m_db_table(opts))
|
||||
output.append("DELETE FROM packages WHERE label = '%s';" % mod._MODELS[0]._meta.app_label)
|
||||
output.append("DELETE FROM auth_permissions WHERE package = '%s';" % mod._MODELS[0]._meta.app_label)
|
||||
output.append("DELETE FROM content_types WHERE package = '%s';" % mod._MODELS[0]._meta.app_label)
|
||||
|
||||
Reference in New Issue
Block a user