Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Small code cleanup -- changed django.core.management.get_sql_delete t…

…o 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
  • Loading branch information...
commit 895d23267115412ab7344ce7668adb1efa7f8e00 1 parent d965694
@adrianholovaty adrianholovaty authored
Showing with 7 additions and 7 deletions.
  1. +3 −3 django/core/management.py
  2. +4 −4 django/core/meta.py
View
6 django/core/management.py
@@ -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)
View
8 django/core/meta.py
@@ -1614,10 +1614,6 @@ def get_db_prep_lookup(self, lookup_type, value):
return []
raise TypeError, "Field has invalid lookup: %s" % lookup_type
- def get_m2m_db_table(self, original_opts):
- "Returns the name of the DB table for this field's relationship."
- return '%s_%s' % (original_opts.db_table, self.name)
-
def has_default(self):
"Returns a boolean of whether this field has a default value."
return self.default != NOT_PROVIDED
@@ -2067,6 +2063,10 @@ def get_manipulator_field_objs(self):
choices = self.get_choices(include_blank=False)
return [curry(formfields.SelectMultipleField, size=min(max(len(choices), 5), 15), choices=choices)]
+ def get_m2m_db_table(self, original_opts):
+ "Returns the name of the many-to-many 'join' table."
+ return '%s_%s' % (original_opts.db_table, self.name)
+
class OneToOneField(IntegerField):
def __init__(self, to, to_field=None, rel_name=None, **kwargs):
kwargs['name'] = kwargs.get('name', 'id')
Please sign in to comment.
Something went wrong with that request. Please try again.