django-model-utils/tests/test_inheritance_iterable.py

19 lines
575 B
Python
Raw Normal View History

from __future__ import annotations
from django.db.models import Prefetch
2020-11-29 20:58:00 +00:00
from django.test import TestCase
2020-11-29 20:58:00 +00:00
from tests.models import InheritanceManagerTestChild1, InheritanceManagerTestParent
class InheritanceIterableTest(TestCase):
def test_prefetch(self):
qs = InheritanceManagerTestChild1.objects.all().prefetch_related(
Prefetch(
'normal_field',
queryset=InheritanceManagerTestParent.objects.all(),
to_attr='normal_field_prefetched'
)
)
self.assertEqual(qs.count(), 0)