Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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


git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b00a5997209792db1b79e9c862d41b749772dec2 1 parent 42dec1e
Adrian Holovaty adrianholovaty authored
Showing with 7 additions and 1 deletion.
  1. +7 −1 django/db/models/
8 django/db/models/
@@ -24,8 +24,14 @@ def __new__(cls, name, bases, attrs):
if not bases or bases == (object,):
return type.__new__(cls, name, bases, attrs)
+ mod = attrs.pop('__module__')
+ # Raise ImportError if this model isn't in INSTALLED_APPS.
+ if re.sub('\.models$', '', mod) not in settings.INSTALLED_APPS:
+ raise ImportError, "INSTALLED_APPS must contain %r in order for you to use this model." % mod
# Create the class.
- new_class = type.__new__(cls, name, bases, {'__module__': attrs.pop('__module__')})
+ new_class = type.__new__(cls, name, bases, {'__module__': mod})
new_class.add_to_class('_meta', Options(attrs.pop('Meta', None)))
new_class.add_to_class('DoesNotExist', types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {}))
Please sign in to comment.
Something went wrong with that request. Please try again.