diff options
| author | Tim Graham <timograham@gmail.com> | 2013-07-16 09:10:04 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-07-24 06:56:33 -0400 |
| commit | 31c13a99bb9ebdaf12ccab4e880c5da930d86e79 (patch) | |
| tree | d7b2fcf5cbc526bf63ffe1a3b521ccc0e3f1d39c /django/db/models | |
| parent | c928725b933ff479c04e8a7fb74c4dc2ba138aa7 (diff) | |
Fixed #14300 -- Fixed initial SQL location if models is a package.
Thanks al_the_x for the report and fheinz for the draft patch.
Diffstat (limited to 'django/db/models')
| -rw-r--r-- | django/db/models/__init__.py | 2 | ||||
| -rw-r--r-- | django/db/models/loading.py | 16 |
2 files changed, 13 insertions, 5 deletions
diff --git a/django/db/models/__init__.py b/django/db/models/__init__.py index 4d310e480b..33151e068d 100644 --- a/django/db/models/__init__.py +++ b/django/db/models/__init__.py @@ -1,7 +1,7 @@ from functools import wraps from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured -from django.db.models.loading import get_apps, get_app_paths, get_app, get_models, get_model, register_models, UnavailableApp +from django.db.models.loading import get_apps, get_app_path, get_app_paths, get_app, get_models, get_model, register_models, UnavailableApp from django.db.models.query import Q from django.db.models.expressions import F from django.db.models.manager import Manager diff --git a/django/db/models/loading.py b/django/db/models/loading.py index 7280051bd8..9a0cadaf37 100644 --- a/django/db/models/loading.py +++ b/django/db/models/loading.py @@ -154,6 +154,16 @@ class AppCache(object): return [elt[0] for elt in apps] + def _get_app_path(self, app): + if hasattr(app, '__path__'): # models/__init__.py package + app_path = app.__path__[0] + else: # models.py module + app_path = app.__file__ + return os.path.dirname(upath(app_path)) + + def get_app_path(self, app_label): + return self._get_app_path(self.get_app(app_label)) + def get_app_paths(self): """ Returns a list of paths to all installed apps. @@ -165,10 +175,7 @@ class AppCache(object): app_paths = [] for app in self.get_apps(): - if hasattr(app, '__path__'): # models/__init__.py package - app_paths.extend([upath(path) for path in app.__path__]) - else: # models.py module - app_paths.append(upath(app.__file__)) + app_paths.append(self._get_app_path(app)) return app_paths def get_app(self, app_label, emptyOK=False): @@ -321,6 +328,7 @@ cache = AppCache() # These methods were always module level, so are kept that way for backwards # compatibility. get_apps = cache.get_apps +get_app_path = cache.get_app_path get_app_paths = cache.get_app_paths get_app = cache.get_app get_app_errors = cache.get_app_errors |
