Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
adrianholovaty committed Feb 27, 2006
1 parent 42dec1e commit b00a599
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion django/db/models/base.py
Expand Up @@ -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,), {}))

Expand Down

0 comments on commit b00a599

Please sign in to comment.