diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2006-06-28 01:53:30 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2006-06-28 01:53:30 +0000 |
| commit | d6c95e93a7a6b31e68789dc586b2cfa446cf8c50 (patch) | |
| tree | 6c8b69da312f2a02a59ab6dcc2becbccca319ae7 /django/db/models/loading.py | |
| parent | 54e5b9aa21736859d7d8899cbeda9fe91aee6e4f (diff) | |
Fixed #1812 -- permit apps without models (without disguising other errors).
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3221 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models/loading.py')
| -rw-r--r-- | django/db/models/loading.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/django/db/models/loading.py b/django/db/models/loading.py index 10ff3bb8d8..3d34845147 100644 --- a/django/db/models/loading.py +++ b/django/db/models/loading.py @@ -32,18 +32,25 @@ def get_apps(): _app_errors[app_name] = e return _app_list -def get_app(app_label): - "Returns the module containing the models for the given app_label." +def get_app(app_label, emptyOK = False): + "Returns the module containing the models for the given app_label. If the app has no models in it and 'emptyOK' is True, returns None." get_apps() # Run get_apps() to populate the _app_list cache. Slightly hackish. for app_name in settings.INSTALLED_APPS: if app_label == app_name.split('.')[-1]: - return load_app(app_name) + mod = load_app(app_name) + if mod is None: + if emptyOK: + return None + else: + return mod raise ImproperlyConfigured, "App with label %s could not be found" % app_label def load_app(app_name): "Loads the app with the provided fully qualified name, and returns the model module." global _app_list mod = __import__(app_name, '', '', ['models']) + if not hasattr(mod, 'models'): + return None if mod.models not in _app_list: _app_list.append(mod.models) return mod.models |
