summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
Diffstat (limited to 'django/db')
-rw-r--r--django/db/__init__.py5
-rw-r--r--django/db/models/loading.py15
2 files changed, 12 insertions, 8 deletions
diff --git a/django/db/__init__.py b/django/db/__init__.py
index da1544f8cd..dde2f2eb22 100644
--- a/django/db/__init__.py
+++ b/django/db/__init__.py
@@ -3,6 +3,7 @@ from django.conf import settings
from django.core import signals
from django.core.exceptions import ImproperlyConfigured
from django.utils.functional import curry
+from django.utils.importlib import import_module
__all__ = ('backend', 'connection', 'DatabaseError', 'IntegrityError')
@@ -13,12 +14,12 @@ def load_backend(backend_name):
try:
# Most of the time, the database backend will be one of the official
# backends that ships with Django, so look there first.
- return __import__('django.db.backends.%s.base' % backend_name, {}, {}, [''])
+ return import_module('.base', 'django.db.backends.%s' % settings.DATABASE_ENGINE)
except ImportError, e:
# If the import failed, we might be looking for a database backend
# distributed external to Django. So we'll try that next.
try:
- return __import__('%s.base' % backend_name, {}, {}, [''])
+ return import_module('.base', backend_name)
except ImportError, e_user:
# The database backend wasn't found. Display a helpful error message
# listing all possible (built-in) database backends.
diff --git a/django/db/models/loading.py b/django/db/models/loading.py
index 6837e070ac..e07aab4efe 100644
--- a/django/db/models/loading.py
+++ b/django/db/models/loading.py
@@ -3,6 +3,7 @@
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.datastructures import SortedDict
+from django.utils.importlib import import_module
import sys
import os
@@ -69,9 +70,10 @@ class AppCache(object):
"""
self.handled[app_name] = None
self.nesting_level += 1
- mod = __import__(app_name, {}, {}, ['models'])
- self.nesting_level -= 1
- if not hasattr(mod, 'models'):
+ try:
+ models = import_module('.models', app_name)
+ except ImportError:
+ self.nesting_level -= 1
if can_postpone:
# Either the app has no models, or the package is still being
# imported by Python and the model module isn't available yet.
@@ -79,9 +81,10 @@ class AppCache(object):
# populate).
self.postponed.append(app_name)
return None
- if mod.models not in self.app_store:
- self.app_store[mod.models] = len(self.app_store)
- return mod.models
+ self.nesting_level -= 1
+ if models not in self.app_store:
+ self.app_store[models] = len(self.app_store)
+ return models
def app_cache_ready(self):
"""