summaryrefslogtreecommitdiff
path: root/tests/model_inheritance
diff options
context:
space:
mode:
authorJames Pulec <jpulec@gmail.com>2015-09-29 10:52:26 -0700
committerTim Graham <timograham@gmail.com>2016-01-28 11:10:47 -0500
commitf05722a08a11b2e6c6c9acdf2bacd6a6128ccbb0 (patch)
treefabf7b0a182135926414d6608239d334292c61e9 /tests/model_inheritance
parent5453aa66cfdf228f40dc1997d811ca986de405a3 (diff)
Fixed #25354 -- Added class/app_label interpolation for related_query_name.
Diffstat (limited to 'tests/model_inheritance')
-rw-r--r--tests/model_inheritance/models.py7
-rw-r--r--tests/model_inheritance/tests.py9
2 files changed, 15 insertions, 1 deletions
diff --git a/tests/model_inheritance/models.py b/tests/model_inheritance/models.py
index 22086ca11d..652eea4eaa 100644
--- a/tests/model_inheritance/models.py
+++ b/tests/model_inheritance/models.py
@@ -56,7 +56,12 @@ class Post(models.Model):
@python_2_unicode_compatible
class Attachment(models.Model):
- post = models.ForeignKey(Post, models.CASCADE, related_name='attached_%(class)s_set')
+ post = models.ForeignKey(
+ Post,
+ models.CASCADE,
+ related_name='attached_%(class)s_set',
+ related_query_name='attached_%(app_label)s_%(class)ss',
+ )
content = models.TextField()
class Meta:
diff --git a/tests/model_inheritance/tests.py b/tests/model_inheritance/tests.py
index 336ddf3e15..a6661d439e 100644
--- a/tests/model_inheritance/tests.py
+++ b/tests/model_inheritance/tests.py
@@ -72,6 +72,15 @@ class ModelInheritanceTests(TestCase):
AttributeError, getattr, post, "attached_%(class)s_set"
)
+ def test_model_with_distinct_related_query_name(self):
+ self.assertQuerysetEqual(Post.objects.filter(attached_model_inheritance_comments__is_spam=True), [])
+
+ # The Post model doesn't have a related query accessor based on
+ # related_name (attached_comment_set).
+ msg = "Cannot resolve keyword 'attached_comment_set' into field."
+ with self.assertRaisesMessage(FieldError, msg):
+ Post.objects.filter(attached_comment_set__is_spam=True)
+
def test_meta_fields_and_ordering(self):
# Make sure Restaurant and ItalianRestaurant have the right fields in
# the right order.