1. Luke Plant
  2. django

Commits

art...@bcc190cf-cafb-0310-a4f2-bffc1f526a37  committed c6fcfab

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

  • Participants
  • Parent commits 27b224c
  • Branches soc2010/app-loading

Comments (0)

Files changed (2)

File django/core/apps.py

View file
  • Ignore whitespace
         self.name = name
         self.verbose_name = _(name.title())
         self.verbose_name_plural = _(name.title())
+        self.db_prefix = name
         self.errors = []
         self.models = []
         self.module = None
         self._populate()
         self.write_lock.acquire()
         try:
-            for app_name in settings.INSTALLED_APPS:
+            for app_name in self.installed_apps:
                 if app_label == app_name.split('.')[-1]:
                     mod = self.load_app(app_name, False)
                     if mod is None:

File django/db/models/options.py

View file
  • Ignore whitespace
 from bisect import bisect
 
 from django.conf import settings
+from django.core.apps import cache
 from django.db.models.related import RelatedObject
 from django.db.models.fields.related import ManyToManyRel
 from django.db.models.fields import AutoField, FieldDoesNotExist
             self.verbose_name_plural = string_concat(self.verbose_name, 's')
         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:
-            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())
 
     def _prepare(self, model):