Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #15903 -- Allowed not-installed models to still be referenced i…

…n related fields. Missed case from r16053.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16106 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c85b765288b2c36c948493a99706550eaf41a0b5 1 parent 2f9c52d
Carl Meyer carljm authored
12 django/db/models/loading.py
View
@@ -159,7 +159,8 @@ def get_app_errors(self):
return self.app_errors
def get_models(self, app_mod=None,
- include_auto_created=False, include_deferred=False):
+ include_auto_created=False, include_deferred=False,
+ only_installed=True):
"""
Given a module containing models, returns a list of the models.
Otherwise returns a list of all installed models.
@@ -172,7 +173,7 @@ def get_models(self, app_mod=None,
queries are *not* included in the list of models. However, if
you specify include_deferred, they will be.
"""
- cache_key = (app_mod, include_auto_created, include_deferred)
+ cache_key = (app_mod, include_auto_created, include_deferred, only_installed)
try:
return self._get_models_cache[cache_key]
except KeyError:
@@ -185,8 +186,11 @@ def get_models(self, app_mod=None,
else:
app_list = []
else:
- app_list = [self.app_models.get(app_label, SortedDict())
- for app_label in self.app_labels.iterkeys()]
+ if only_installed:
+ app_list = [self.app_models.get(app_label, SortedDict())
+ for app_label in self.app_labels.iterkeys()]
+ else:
+ app_list = self.app_models.itervalues()
model_list = []
for app in app_list:
model_list.extend(
2  django/db/models/options.py
View
@@ -383,7 +383,7 @@ def _fill_related_objects_cache(self):
cache[obj] = parent
else:
cache[obj] = model
- for klass in get_models(include_auto_created=True):
+ for klass in get_models(include_auto_created=True, only_installed=False):
for f in klass._meta.local_fields:
if f.rel and not isinstance(f.rel.to, str) and self == f.rel.to._meta:
cache[RelatedObject(f.rel.to, klass, f)] = None
4 tests/regressiontests/app_loading/not_installed/models.py
View
@@ -3,3 +3,7 @@
class NotInstalledModel(models.Model):
pass
+
+
+class RelatedModel(models.Model):
+ not_installed = models.ForeignKey(NotInstalledModel)
25 tests/regressiontests/app_loading/tests.py
View
@@ -85,8 +85,8 @@ def test_egg5(self):
class GetModelsTest(TestCase):
def setUp(self):
- import not_installed.models
- self.not_installed_module = not_installed.models
+ from .not_installed import models
+ self.not_installed_module = models
def test_get_model_only_returns_installed_models(self):
@@ -94,6 +94,13 @@ def test_get_model_only_returns_installed_models(self):
get_model("not_installed", "NotInstalledModel"), None)
+ def test_get_model_with_not_installed(self):
+ self.assertEqual(
+ get_model(
+ "not_installed", "NotInstalledModel", only_installed=False),
+ self.not_installed_module.NotInstalledModel)
+
+
def test_get_models_only_returns_installed_models(self):
self.assertFalse(
"NotInstalledModel" in
@@ -102,3 +109,17 @@ def test_get_models_only_returns_installed_models(self):
def test_get_models_with_app_label_only_returns_installed_models(self):
self.assertEqual(get_models(self.not_installed_module), [])
+
+
+ def test_get_models_with_not_installed(self):
+ self.assertTrue(
+ "NotInstalledModel" in [
+ m.__name__ for m in get_models(only_installed=False)])
+
+
+class NotInstalledModelsTest(TestCase):
+ def test_related_not_installed_model(self):
+ from .not_installed.models import NotInstalledModel
+ self.assertEqual(
+ set(NotInstalledModel._meta.get_all_field_names()),
+ set(["id", "relatedmodel"]))
Please sign in to comment.
Something went wrong with that request. Please try again.