2023-03-21 13:21:03 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2017-06-23 13:51:32 +00:00
|
|
|
from django.db.models import Prefetch
|
2020-11-29 20:58:00 +00:00
|
|
|
from django.test import TestCase
|
2017-06-23 13:51:32 +00:00
|
|
|
|
2020-11-29 20:58:00 +00:00
|
|
|
from tests.models import InheritanceManagerTestChild1, InheritanceManagerTestParent
|
2017-06-23 13:51:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class InheritanceIterableTest(TestCase):
|
2023-03-22 17:50:18 +00:00
|
|
|
def test_prefetch(self) -> None:
|
2017-06-23 13:51:32 +00:00
|
|
|
qs = InheritanceManagerTestChild1.objects.all().prefetch_related(
|
|
|
|
|
Prefetch(
|
|
|
|
|
'normal_field',
|
|
|
|
|
queryset=InheritanceManagerTestParent.objects.all(),
|
|
|
|
|
to_attr='normal_field_prefetched'
|
|
|
|
|
)
|
|
|
|
|
)
|
2020-08-12 09:48:24 +00:00
|
|
|
self.assertEqual(qs.count(), 0)
|