Normalized Model._meta.installed.

Used the information from the app cache instead of creating a duplicate
based on INSTALLED_APPS.

Model._meta.installed is no longer writable. It was a rather sketchy way
to alter private internals anyway.
This commit is contained in:
Aymeric Augustin 2013-12-16 19:30:33 +01:00
parent 0242c56fd8
commit 7eea9bf303
7 changed files with 34 additions and 23 deletions

View file

@ -91,13 +91,21 @@ class Options(object):
# A custom AppCache to use, if you're making a separate model set.
self.app_cache = app_cache
@property
def app_config(self):
# Don't go through get_app_config to avoid triggering populate().
return self.app_cache.app_configs[self.app_label]
@property
def installed(self):
return self.app_config.installed
def contribute_to_class(self, cls, name):
from django.db import connection
from django.db.backends.utils import truncate_name
cls._meta = self
self.model = cls
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.model_name = self.object_name.lower()