Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

magic-removal: Fixed #1179 -- Models not in INSTALLED_APPS now raise …

…ImportError

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2406 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b00a5997209792db1b79e9c862d41b749772dec2 1 parent 42dec1e
Adrian Holovaty authored February 27, 2006

Showing 1 changed file with 7 additions and 1 deletion. Show diff stats Hide diff stats

  1. 8  django/db/models/base.py
8  django/db/models/base.py
@@ -24,8 +24,14 @@ def __new__(cls, name, bases, attrs):
24 24
         if not bases or bases == (object,):
25 25
             return type.__new__(cls, name, bases, attrs)
26 26
 
  27
+        mod = attrs.pop('__module__')
  28
+
  29
+        # Raise ImportError if this model isn't in INSTALLED_APPS.
  30
+        if re.sub('\.models$', '', mod) not in settings.INSTALLED_APPS:
  31
+            raise ImportError, "INSTALLED_APPS must contain %r in order for you to use this model." % mod
  32
+
27 33
         # Create the class.
28  
-        new_class = type.__new__(cls, name, bases, {'__module__': attrs.pop('__module__')})
  34
+        new_class = type.__new__(cls, name, bases, {'__module__': mod})
29 35
         new_class.add_to_class('_meta', Options(attrs.pop('Meta', None)))
30 36
         new_class.add_to_class('DoesNotExist', types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {}))
31 37
 

0 notes on commit b00a599

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