mirror of
https://github.com/django/django.git
synced 2025-06-03 18:49:12 +00:00
Refs #29789 -- Added more tests for FilteredRelation with condition outside of relation name.
This commit is contained in:
parent
afc880571d
commit
e4a5527d1d
@ -11,8 +11,10 @@ from django.db.models import (
|
|||||||
FilteredRelation,
|
FilteredRelation,
|
||||||
Q,
|
Q,
|
||||||
Sum,
|
Sum,
|
||||||
|
Value,
|
||||||
When,
|
When,
|
||||||
)
|
)
|
||||||
|
from django.db.models.functions import Concat
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.testcases import skipUnlessDBFeature
|
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):
|
def test_condition_deeper_relation_name(self):
|
||||||
msg = (
|
msg = (
|
||||||
"FilteredRelation's condition doesn't support nested relations "
|
"FilteredRelation's condition doesn't support nested relations "
|
||||||
|
Loading…
x
Reference in New Issue
Block a user