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 -- 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
Adrian Holovaty authored April 11, 2006
9  django/db/models/base.py
@@ -14,7 +14,6 @@
14 14
 from django.utils.datastructures import SortedDict
15 15
 from django.utils.functional import curry
16 16
 from django.conf import settings
17  
-import re
18 17
 import types
19 18
 import sys
20 19
 import os
@@ -26,14 +25,8 @@ def __new__(cls, name, bases, attrs):
26 25
         if not bases or bases == (object,):
27 26
             return type.__new__(cls, name, bases, attrs)
28 27
 
29  
-        mod = attrs.pop('__module__')
30  
-
31  
-        # Raise ImportError if this model isn't in INSTALLED_APPS.
32  
-        if re.sub('\.models$', '', mod) not in settings.INSTALLED_APPS:
33  
-            raise ImportError, "INSTALLED_APPS must contain %r in order for you to use this model." % re.sub('\.models$', '', mod)
34  
-
35 28
         # Create the class.
36  
-        new_class = type.__new__(cls, name, bases, {'__module__': mod})
  29
+        new_class = type.__new__(cls, name, bases, {'__module__': attrs.pop('__module__')})
37 30
         new_class.add_to_class('_meta', Options(attrs.pop('Meta', None)))
38 31
         new_class.add_to_class('DoesNotExist', types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {}))
39 32
 
2  django/db/models/options.py
... ...
@@ -1,3 +1,4 @@
  1
+from django.conf import settings
1 2
 from django.db.models.related import RelatedObject
2 3
 from django.db.models.fields.related import ManyToManyRel
3 4
 from django.db.models.fields import AutoField, FieldDoesNotExist
@@ -35,6 +36,7 @@ def __init__(self, meta):
35 36
 
36 37
     def contribute_to_class(self, cls, name):
37 38
         cls._meta = self
  39
+        self.installed = re.sub('\.models$', '', cls.__module__) in settings.INSTALLED_APPS
38 40
         # First, construct the default values for these options.
39 41
         self.object_name = cls.__name__
40 42
         self.module_name = self.object_name.lower()

0 notes on commit 8792dce

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