summaryrefslogtreecommitdiff
path: root/tests/filtered_relation
diff options
context:
space:
mode:
authorFrancesco Panico <panico.francesco@gmail.com>2023-07-21 10:59:17 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-07-21 12:03:42 +0200
commite4a5527d1dc2f8183883931560f3a6dcdef0ab0c (patch)
tree51f1461d7fe438661735a0de8b8be67c8d68ff03 /tests/filtered_relation
parentafc880571d5f5a16b977070b15014f9583524898 (diff)
Refs #29789 -- Added more tests for FilteredRelation with condition outside of relation name.
Diffstat (limited to 'tests/filtered_relation')
-rw-r--r--tests/filtered_relation/tests.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/filtered_relation/tests.py b/tests/filtered_relation/tests.py
index 2cceeb82e7..f74e3978f9 100644
--- a/tests/filtered_relation/tests.py
+++ b/tests/filtered_relation/tests.py
@@ -11,8 +11,10 @@ from django.db.models import (
FilteredRelation,
Q,
Sum,
+ Value,
When,
)
+from django.db.models.functions import Concat
from django.test import TestCase
from django.test.testcases import skipUnlessDBFeature
@@ -629,6 +631,26 @@ class FilteredRelationTests(TestCase):
),
)
+ def test_condition_with_exact_lookup_outside_relation_name(self):
+ qs = Author.objects.annotate(
+ book_editor=FilteredRelation(
+ "book__editor",
+ condition=Q(book__author__name="book"),
+ ),
+ ).filter(book_editor__isnull=True)
+ self.assertEqual(qs.count(), 4)
+
+ def test_condition_with_func_and_lookup_outside_relation_name(self):
+ qs = Author.objects.annotate(
+ book_editor=FilteredRelation(
+ "book__editor",
+ condition=Q(
+ book__title=Concat(Value("The book by "), F("book__author__name"))
+ ),
+ ),
+ ).filter(book_editor__isnull=False)
+ self.assertEquals(qs.count(), 1)
+
def test_condition_deeper_relation_name(self):
msg = (
"FilteredRelation's condition doesn't support nested relations "