Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1812 -- permit apps without models (without disguising other e…

…rrors).

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3221 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d6c95e93a7a6b31e68789dc586b2cfa446cf8c50 1 parent 54e5b9a
Malcolm Tredinnick authored June 28, 2006

Showing 1 changed file with 10 additions and 3 deletions. Show diff stats Hide diff stats

  1. 13  django/db/models/loading.py
13  django/db/models/loading.py
@@ -32,18 +32,25 @@ def get_apps():
32 32
                 _app_errors[app_name] = e
33 33
     return _app_list
34 34
 
35  
-def get_app(app_label):
36  
-    "Returns the module containing the models for the given app_label."
  35
+def get_app(app_label, emptyOK = False):
  36
+    "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."
37 37
     get_apps() # Run get_apps() to populate the _app_list cache. Slightly hackish.
38 38
     for app_name in settings.INSTALLED_APPS:
39 39
         if app_label == app_name.split('.')[-1]:
40  
-            return load_app(app_name)
  40
+            mod = load_app(app_name)
  41
+            if mod is None:
  42
+                if emptyOK:
  43
+                    return None
  44
+            else:
  45
+                return mod
41 46
     raise ImproperlyConfigured, "App with label %s could not be found" % app_label
42 47
 
43 48
 def load_app(app_name):
44 49
     "Loads the app with the provided fully qualified name, and returns the model module."
45 50
     global _app_list
46 51
     mod = __import__(app_name, '', '', ['models'])
  52
+    if not hasattr(mod, 'models'):
  53
+        return None
47 54
     if mod.models not in _app_list:
48 55
         _app_list.append(mod.models)
49 56
     return mod.models

0 notes on commit d6c95e9

Please sign in to comment.
Something went wrong with that request. Please try again.