Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

magic-removal: Fixed #1179 -- Importing a model no longer raises Impo…

…rtError if it's not in INSTALLED_APPS. Instead, Model._meta.installed is set to either True or False, so you can check it

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2655 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8792dceb74cdac4c2fc4379e995f5eafc2aa77bd 1 parent 2fade6a
@adrianholovaty adrianholovaty authored
Showing with 3 additions and 8 deletions.
  1. +1 −8 django/db/models/base.py
  2. +2 −0  django/db/models/options.py
View
9 django/db/models/base.py
@@ -14,7 +14,6 @@
from django.utils.datastructures import SortedDict
from django.utils.functional import curry
from django.conf import settings
-import re
import types
import sys
import os
@@ -26,14 +25,8 @@ 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." % re.sub('\.models$', '', mod)
-
# Create the class.
- new_class = type.__new__(cls, name, bases, {'__module__': mod})
+ new_class = type.__new__(cls, name, bases, {'__module__': attrs.pop('__module__')})
new_class.add_to_class('_meta', Options(attrs.pop('Meta', None)))
new_class.add_to_class('DoesNotExist', types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {}))
View
2  django/db/models/options.py
@@ -1,3 +1,4 @@
+from django.conf import settings
from django.db.models.related import RelatedObject
from django.db.models.fields.related import ManyToManyRel
from django.db.models.fields import AutoField, FieldDoesNotExist
@@ -35,6 +36,7 @@ def __init__(self, meta):
def contribute_to_class(self, cls, name):
cls._meta = self
+ self.installed = re.sub('\.models$', '', cls.__module__) in settings.INSTALLED_APPS
# First, construct the default values for these options.
self.object_name = cls.__name__
self.module_name = self.object_name.lower()
Please sign in to comment.
Something went wrong with that request. Please try again.