diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py index 53609ba3f8..87a0c49846 100644 --- a/django/contrib/auth/models.py +++ b/django/contrib/auth/models.py @@ -132,7 +132,7 @@ class User(models.Model): # The SQL below works out to the following, after DB quoting: # cursor.execute(""" # SELECT p.package, p.codename - # FROM auth_permissions p, auth_groups_permissions gp, auth_users_groups ug + # FROM auth_permission p, auth_group_permissions gp, auth_user_groups ug # WHERE p.id = gp.permission_id # AND gp.group_id = ug.group_id # AND ug.user_id = %s""", [self.id]) @@ -143,7 +143,7 @@ class User(models.Model): AND gp.%s = ug.%s AND ug.%s = %%s""" % ( backend.quote_name('package'), backend.quote_name('codename'), - backend.quote_name('auth_permissions'), backend.quote_name('auth_groups_permissions'), + backend.quote_name('auth_permission'), backend.quote_name('auth_group_permissions'), backend.quote_name('auth_users_groups'), backend.quote_name('id'), backend.quote_name('permission_id'), backend.quote_name('group_id'), backend.quote_name('group_id'), backend.quote_name('user_id')) diff --git a/django/contrib/comments/models.py b/django/contrib/comments/models.py index 22a4858241..98c5f239a7 100644 --- a/django/contrib/comments/models.py +++ b/django/contrib/comments/models.py @@ -86,7 +86,6 @@ class Comment(models.Model): site = models.ForeignKey(Site) objects = CommentManager() class Meta: - db_table = 'comments' verbose_name = _('Comment') verbose_name_plural = _('Comments') ordering = ('-submit_date',) @@ -173,7 +172,6 @@ class FreeComment(models.Model): approved = models.BooleanField(_('approved by staff')) site = models.ForeignKey(Site) class Meta: - db_table = 'comments_free' verbose_name = _('Free comment') verbose_name_plural = _('Free comments') ordering = ('-submit_date',) @@ -266,7 +264,6 @@ class UserFlag(models.Model): flag_date = models.DateTimeField(_('flag date'), auto_now_add=True) objects = UserFlagManager() class Meta: - db_table = 'comments_user_flags' verbose_name = _('User flag') verbose_name_plural = _('User flags') unique_together = (('user', 'comment'),) @@ -279,7 +276,6 @@ class ModeratorDeletion(models.Model): comment = models.ForeignKey(Comment) deletion_date = models.DateTimeField(_('deletion date'), auto_now_add=True) class Meta: - db_table = 'comments_moderator_deletions' verbose_name = _('Moderator deletion') verbose_name_plural = _('Moderator deletions') unique_together = (('user', 'comment'),) diff --git a/django/contrib/contenttypes/models.py b/django/contrib/contenttypes/models.py index 2621bbaddc..27a7429c7c 100644 --- a/django/contrib/contenttypes/models.py +++ b/django/contrib/contenttypes/models.py @@ -7,7 +7,7 @@ class Package(models.Model): class Meta: verbose_name = _('package') verbose_name_plural = _('packages') - db_table = 'packages' + db_table = 'django_package' ordering = ('name',) def __repr__(self): @@ -20,7 +20,7 @@ class ContentType(models.Model): class Meta: verbose_name = _('content type') verbose_name_plural = _('content types') - db_table = 'content_types' + db_table = 'django_content_type' ordering = ('package', 'name') unique_together = (('package', 'python_module_name'),) diff --git a/django/contrib/flatpages/models.py b/django/contrib/flatpages/models.py index 849281510e..a60a536923 100644 --- a/django/contrib/flatpages/models.py +++ b/django/contrib/flatpages/models.py @@ -14,7 +14,7 @@ class FlatPage(models.Model): registration_required = models.BooleanField(_('registration required'), help_text=_("If this is checked, only logged-in users will be able to view the page.")) sites = models.ManyToManyField(Site) class Meta: - db_table = 'django_flatpages' + db_table = 'django_flatpage' verbose_name = _('flat page') verbose_name_plural = _('flat pages') ordering = ('url',) diff --git a/django/contrib/redirects/models.py b/django/contrib/redirects/models.py index 608a304ea2..3f01996b9c 100644 --- a/django/contrib/redirects/models.py +++ b/django/contrib/redirects/models.py @@ -11,7 +11,7 @@ class Redirect(models.Model): class Meta: verbose_name = _('redirect') verbose_name_plural = _('redirects') - db_table = 'django_redirects' + db_table = 'django_redirect' unique_together=(('site', 'old_path'),) ordering = ('old_path',) class Admin: diff --git a/django/contrib/sessions/models.py b/django/contrib/sessions/models.py index f5abde73b1..1d4a148dad 100644 --- a/django/contrib/sessions/models.py +++ b/django/contrib/sessions/models.py @@ -37,7 +37,7 @@ class Session(models.Model): expire_date = models.DateTimeField(_('expire date')) objects = SessionManager() class Meta: - db_table = 'django_sessions' + db_table = 'django_session' verbose_name = _('session') verbose_name_plural = _('sessions') module_constants = { diff --git a/django/contrib/sites/models.py b/django/contrib/sites/models.py index 5844d65e52..6610dc6434 100644 --- a/django/contrib/sites/models.py +++ b/django/contrib/sites/models.py @@ -11,7 +11,7 @@ class Site(models.Model): name = models.CharField(_('display name'), maxlength=50) objects = SiteManager() class Meta: - db_table = 'sites' + db_table = 'django_site' verbose_name = _('site') verbose_name_plural = _('sites') ordering = ('domain',) diff --git a/django/core/management.py b/django/core/management.py index 3072759cf2..a30d08abdd 100644 --- a/django/core/management.py +++ b/django/core/management.py @@ -29,7 +29,7 @@ INVALID_PROJECT_NAMES = ('django', 'test') def _get_packages_insert(app_label): from django.db import backend return "INSERT INTO %s (%s, %s) VALUES ('%s', '%s');" % \ - (backend.quote_name('packages'), backend.quote_name('label'), backend.quote_name('name'), + (backend.quote_name('django_package'), backend.quote_name('label'), backend.quote_name('name'), app_label, app_label) def _get_permission_codename(action, opts): @@ -46,13 +46,13 @@ def _get_all_permissions(opts): def _get_permission_insert(name, codename, opts): from django.db import backend return "INSERT INTO %s (%s, %s, %s) VALUES ('%s', '%s', '%s');" % \ - (backend.quote_name('auth_permissions'), backend.quote_name('name'), backend.quote_name('package'), + (backend.quote_name('auth_permission'), backend.quote_name('name'), backend.quote_name('package'), backend.quote_name('codename'), name.replace("'", "''"), opts.app_label, codename) def _get_contenttype_insert(opts): from django.db import backend return "INSERT INTO %s (%s, %s, %s) VALUES ('%s', '%s', '%s');" % \ - (backend.quote_name('content_types'), backend.quote_name('name'), backend.quote_name('package'), + (backend.quote_name('django_content_type'), backend.quote_name('name'), backend.quote_name('package'), backend.quote_name('python_module_name'), opts.verbose_name, opts.app_label, opts.module_name) def _is_valid_dir_name(s): @@ -249,18 +249,18 @@ def get_sql_delete(app): app_label = app_models[0]._meta.app_label - # Delete from packages, auth_permissions, content_types. + # Delete from django_package, auth_permission, django_content_type. output.append("DELETE FROM %s WHERE %s = '%s';" % \ - (backend.quote_name('packages'), backend.quote_name('label'), app_label)) + (backend.quote_name('django_package'), backend.quote_name('label'), app_label)) output.append("DELETE FROM %s WHERE %s = '%s';" % \ - (backend.quote_name('auth_permissions'), backend.quote_name('package'), app_label)) + (backend.quote_name('auth_permission'), backend.quote_name('package'), app_label)) output.append("DELETE FROM %s WHERE %s = '%s';" % \ - (backend.quote_name('content_types'), backend.quote_name('package'), app_label)) + (backend.quote_name('django_content_type'), backend.quote_name('package'), app_label)) # Delete from the admin log. if cursor is not None: cursor.execute("SELECT %s FROM %s WHERE %s = %%s" % \ - (backend.quote_name('id'), backend.quote_name('content_types'), + (backend.quote_name('id'), backend.quote_name('django_content_type'), backend.quote_name('package')), [app_label]) if admin_log_exists: for row in cursor.fetchall(): @@ -373,7 +373,7 @@ def database_check(app): # Check that the package exists in the database. cursor.execute("SELECT 1 FROM %s WHERE %s = %%s" % \ - (backend.quote_name('packages'), backend.quote_name('label')), [app_label]) + (backend.quote_name('django_package'), backend.quote_name('label')), [app_label]) if has_no_records(cursor): # sys.stderr.write("The '%s' package isn't installed.\n" % app_label) print _get_packages_insert(app_label) @@ -388,13 +388,13 @@ def database_check(app): contenttypes_seen[opts.module_name] = 1 for codename, name in perms: cursor.execute("SELECT 1 FROM %s WHERE %s = %%s AND %s = %%s" % \ - (backend.quote_name('auth_permissions'), backend.quote_name('package'), + (backend.quote_name('auth_permission'), backend.quote_name('package'), backend.quote_name('codename')), (app_label, codename)) if has_no_records(cursor): # sys.stderr.write("The '%s.%s' permission doesn't exist.\n" % (app_label, codename)) print _get_permission_insert(name, codename, opts) cursor.execute("SELECT 1 FROM %s WHERE %s = %%s AND %s = %%s" % \ - (backend.quote_name('content_types'), backend.quote_name('package'), + (backend.quote_name('django_content_type'), backend.quote_name('package'), backend.quote_name('python_module_name')), (app_label, opts.module_name)) if has_no_records(cursor): # sys.stderr.write("The '%s.%s' content type doesn't exist.\n" % (app_label, opts.module_name)) @@ -403,7 +403,7 @@ def database_check(app): # Check that there aren't any *extra* permissions in the DB that the model # doesn't know about. cursor.execute("SELECT %s FROM %s WHERE %s = %%s" % \ - (backend.quote_name('codename'), backend.quote_name('auth_permissions'), + (backend.quote_name('codename'), backend.quote_name('auth_permission'), backend.quote_name('package')), (app_label,)) for row in cursor.fetchall(): try: @@ -411,13 +411,13 @@ def database_check(app): except KeyError: # sys.stderr.write("A permission called '%s.%s' was found in the database but not in the model.\n" % (app_label, row[0])) print "DELETE FROM %s WHERE %s='%s' AND %s = '%s';" % \ - (backend.quote_name('auth_permissions'), backend.quote_name('package'), + (backend.quote_name('auth_permission'), backend.quote_name('package'), app_label, backend.quote_name('codename'), row[0]) # Check that there aren't any *extra* content types in the DB that the # model doesn't know about. cursor.execute("SELECT %s FROM %s WHERE %s = %%s" % \ - (backend.quote_name('python_module_name'), backend.quote_name('content_types'), + (backend.quote_name('python_module_name'), backend.quote_name('django_content_type'), backend.quote_name('package')), (app_label,)) for row in cursor.fetchall(): try: @@ -425,7 +425,7 @@ def database_check(app): except KeyError: # sys.stderr.write("A content type called '%s.%s' was found in the database but not in the model.\n" % (app_label, row[0])) print "DELETE FROM %s WHERE %s='%s' AND %s = '%s';" % \ - (backend.quote_name('content_types'), backend.quote_name('package'), + (backend.quote_name('django_content_type'), backend.quote_name('package'), app_label, backend.quote_name('python_module_name'), row[0]) database_check.help_doc = "Checks that everything is installed in the database for the given model module name(s) and prints SQL statements if needed." database_check.args = APP_ARGS diff --git a/django/db/models/options.py b/django/db/models/options.py index b0e3385fe5..424a4700dd 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -6,8 +6,8 @@ from django.db.models.query import orderlist2sql from bisect import bisect import re -# Calculate the module_name using a poor-man's pluralization. -get_module_name = lambda class_name: class_name.lower() + 's' +# Calculate the module_name by converting to lowercase +get_module_name = lambda class_name: class_name.lower() # Calculate the verbose_name by converting from InitialCaps to "lowercase with spaces". get_verbose_name = lambda class_name: re.sub('([A-Z])', ' \\1', class_name).lower().strip()