1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

[soc2010/app-loading] use the db_prefix attribute to create database tables

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/app-loading@13593 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Arthur Koziel 2010-08-15 22:02:04 +00:00
parent a357ed10be
commit 2f027bf5dd
2 changed files with 6 additions and 3 deletions

View File

@ -25,6 +25,7 @@ class App(object):
self.name = name self.name = name
self.verbose_name = _(name.title()) self.verbose_name = _(name.title())
self.verbose_name_plural = _(name.title()) self.verbose_name_plural = _(name.title())
self.db_prefix = name
self.errors = [] self.errors = []
self.models = [] self.models = []
self.module = None self.module = None
@ -201,7 +202,7 @@ class AppCache(object):
self._populate() self._populate()
self.write_lock.acquire() self.write_lock.acquire()
try: try:
for app_name in settings.INSTALLED_APPS: for app_name in self.installed_apps:
if app_label == app_name.split('.')[-1]: if app_label == app_name.split('.')[-1]:
mod = self.load_app(app_name, False) mod = self.load_app(app_name, False)
if mod is None: if mod is None:

View File

@ -2,6 +2,7 @@ import re
from bisect import bisect from bisect import bisect
from django.conf import settings from django.conf import settings
from django.core.apps import cache
from django.db.models.related import RelatedObject from django.db.models.related import RelatedObject
from django.db.models.fields.related import ManyToManyRel from django.db.models.fields.related import ManyToManyRel
from django.db.models.fields import AutoField, FieldDoesNotExist from django.db.models.fields import AutoField, FieldDoesNotExist
@ -95,9 +96,10 @@ class Options(object):
self.verbose_name_plural = string_concat(self.verbose_name, 's') self.verbose_name_plural = string_concat(self.verbose_name, 's')
del self.meta del self.meta
# If the db_table wasn't provided, use the app_label + module_name. # If the db_table wasn't provided, use the db_prefix + module_name.
if not self.db_table: if not self.db_table:
self.db_table = "%s_%s" % (self.app_label, self.module_name) app_instance = cache.find_app(self.app_label)
self.db_table = "%s_%s" % (app_instance.db_prefix, self.module_name)
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
def _prepare(self, model): def _prepare(self, model):