mirror of
https://github.com/django/django.git
synced 2025-09-13 14:06:28 +00:00
Moved list of models inside AppConfig instances.
This commit is a refactoring with no change of functionality, according to the following invariants: - An app_label that was in app_configs and app_models stays in app_config and has its 'installed' attribute set to True. - An app_label that was in app_models but not in app_configs is added to app_configs and has its 'installed' attribute set to True. As a consequence, all the code that iterated on app_configs is modified to check for the 'installed' attribute. Code that iterated on app_models is rewritten in terms of app_configs. Many tests that stored and restored the state of the app cache were updated. In the long term, we should reconsider the usefulness of allowing importing models from non-installed applications. This doesn't sound particularly useful, can be a trap in some circumstances, and causes significant complexity in sensitive areas of Django.
This commit is contained in:
parent
2c9e84af4a
commit
b55282b98b
10 changed files with 87 additions and 73 deletions
|
@ -1,7 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import copy
|
||||
|
||||
from django.apps import app_cache
|
||||
from django.conf import settings
|
||||
from django.db import connection
|
||||
|
@ -28,7 +26,7 @@ class TablespacesTests(TestCase):
|
|||
def setUp(self):
|
||||
# The unmanaged models need to be removed after the test in order to
|
||||
# prevent bad interactions with the flush operation in other tests.
|
||||
self.old_app_models = copy.deepcopy(app_cache.app_models)
|
||||
self._old_models = app_cache.app_configs['tablespaces'].models.copy()
|
||||
|
||||
for model in Article, Authors, Reviewers, Scientist:
|
||||
model._meta.managed = True
|
||||
|
@ -37,7 +35,7 @@ class TablespacesTests(TestCase):
|
|||
for model in Article, Authors, Reviewers, Scientist:
|
||||
model._meta.managed = False
|
||||
|
||||
app_cache.app_models = self.old_app_models
|
||||
app_cache.app_configs['tablespaces'].models = self._old_models
|
||||
app_cache._get_models_cache = {}
|
||||
|
||||
def assertNumContains(self, haystack, needle, count):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue