mirror of https://github.com/django/django.git
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,
|
||||
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 "
|
||||
|
|
Loading…
Reference in New Issue