From b00a5997209792db1b79e9c862d41b749772dec2 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Mon, 27 Feb 2006 05:17:08 +0000 Subject: [PATCH] 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 --- django/db/models/base.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/django/db/models/base.py b/django/db/models/base.py index 2d3071edb2..aa2591511a 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -24,8 +24,14 @@ class ModelBase(type): 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,), {}))