1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

magic-removal: Fixed #1179 -- Importing a model no longer raises ImportError 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
This commit is contained in:
Adrian Holovaty 2006-04-11 01:26:24 +00:00
parent 2fade6acac
commit 8792dceb74
2 changed files with 3 additions and 8 deletions

View File

@ -14,7 +14,6 @@ from django.dispatch import dispatcher
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 @@ 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." % 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 File

@ -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 @@ class Options:
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()