summaryrefslogtreecommitdiff
path: root/django/db/models
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2009-03-18 16:55:59 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2009-03-18 16:55:59 +0000
commitc485e236bd7e5ea40c64b2fe54d85dbb15b2fd39 (patch)
treefc5e86abf39b69181b2084f5c39038f1811b6b44 /django/db/models
parentee2f04d79e5bca55637b9bb3301618738a4e342a (diff)
Fixed #8193: all dynamic imports in Django are now done correctly. I know this because Brett Cannon borrowed the time machine and brought Python 2.7's '`importlib` back for inclusion in Django. Thanks for the patch-from-the-future, Brett!
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10088 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models')
-rw-r--r--django/db/models/loading.py15
1 files changed, 9 insertions, 6 deletions
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):
"""