summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Pyrathon <pirosb3@gmail.com>2015-02-10 18:15:54 +0100
committerTim Graham <timograham@gmail.com>2015-02-10 19:55:06 -0500
commit19188826b4aa989475418f1ea9bf8631b04da1e8 (patch)
tree0a005a39819ae21875ea7f6b3eaecb4ece219662
parent1fbe8a2de334bfec5e9b77e36f8a3c1cf2cd70be (diff)
Fixed #24146 -- Allowed model._meta.get_field() to be used after apps.models_ready
-rw-r--r--django/db/models/options.py2
-rw-r--r--tests/admin_checks/models.py1
-rw-r--r--tests/admin_checks/tests.py17
-rw-r--r--tests/model_meta/tests.py4
4 files changed, 21 insertions, 3 deletions
diff --git a/django/db/models/options.py b/django/db/models/options.py
index 83f1eb036a..0b669de121 100644
--- a/django/db/models/options.py
+++ b/django/db/models/options.py
@@ -535,7 +535,7 @@ class Options(object):
except KeyError:
# If the app registry is not ready, reverse fields are
# unavailable, therefore we throw a FieldDoesNotExist exception.
- if not self.apps.ready:
+ if not self.apps.models_ready:
raise FieldDoesNotExist(
"%s has no field named %r. The app cache isn't ready yet, "
"so if this is an auto-created related field, it won't "
diff --git a/tests/admin_checks/models.py b/tests/admin_checks/models.py
index dbb5931c8c..835c26c0dc 100644
--- a/tests/admin_checks/models.py
+++ b/tests/admin_checks/models.py
@@ -49,6 +49,7 @@ class Book(models.Model):
class AuthorsBooks(models.Model):
author = models.ForeignKey(Author)
book = models.ForeignKey(Book)
+ featured = models.BooleanField()
class State(models.Model):
diff --git a/tests/admin_checks/tests.py b/tests/admin_checks/tests.py
index 864609a6c7..7e1902105f 100644
--- a/tests/admin_checks/tests.py
+++ b/tests/admin_checks/tests.py
@@ -667,3 +667,20 @@ class SystemChecksTestCase(TestCase):
)
]
self.assertEqual(errors, expected)
+
+ def test_list_filter_works_on_through_field_even_when_apps_not_ready(self):
+ """
+ Ensure list_filter can access reverse fields even when the app registry
+ is not ready; refs #24146.
+ """
+ class BookAdminWithListFilter(admin.ModelAdmin):
+ list_filter = ['authorsbooks__featured']
+
+ # Temporarily pretending apps are not ready yet. This issue can happen
+ # if the value of 'list_filter' refers to a 'through__field'.
+ Book._meta.apps.ready = False
+ try:
+ errors = BookAdminWithListFilter.check(model=Book)
+ self.assertEqual(errors, [])
+ finally:
+ Book._meta.apps.ready = True
diff --git a/tests/model_meta/tests.py b/tests/model_meta/tests.py
index 4a08b408c6..ef526b7bc4 100644
--- a/tests/model_meta/tests.py
+++ b/tests/model_meta/tests.py
@@ -178,7 +178,7 @@ class GetFieldByNameTests(OptionsBaseTests):
opts = Person._meta
# If apps registry is not ready, get_field() searches over only
# forward fields.
- opts.apps.ready = False
+ opts.apps.models_ready = False
try:
# 'data_abstract' is a forward field, and therefore will be found
self.assertTrue(opts.get_field('data_abstract'))
@@ -191,7 +191,7 @@ class GetFieldByNameTests(OptionsBaseTests):
with self.assertRaisesMessage(FieldDoesNotExist, msg):
opts.get_field('relating_baseperson')
finally:
- opts.apps.ready = True
+ opts.apps.models_ready = True
class RelationTreeTests(TestCase):