diff --git a/AUTHORS.rst b/AUTHORS.rst index 4dd3044..fd350c0 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -15,6 +15,7 @@ Facundo Gaich Felipe Prenholato Filipe Ximenes Gregor Müllegger +Hanley Hansen ivirabyan James Oakley Jannis Leidel diff --git a/model_utils/managers.py b/model_utils/managers.py index 9dc68a2..8e022b4 100644 --- a/model_utils/managers.py +++ b/model_utils/managers.py @@ -7,14 +7,14 @@ try: from django.db.models.query import BaseIterable, ModelIterable except ImportError: # Django 1.8 does not have iterable classes - BaseIterable = object + BaseIterable, ModelIterable = object, object from django.core.exceptions import ObjectDoesNotExist from django.db.models.constants import LOOKUP_SEP from django.utils.six import string_types -class InheritanceIterable(BaseIterable): +class InheritanceIterable(ModelIterable): def __iter__(self): queryset = self.queryset iter = ModelIterable(queryset) diff --git a/tests/test_inheritance_iterable.py b/tests/test_inheritance_iterable.py new file mode 100644 index 0000000..884b763 --- /dev/null +++ b/tests/test_inheritance_iterable.py @@ -0,0 +1,22 @@ +from __future__ import unicode_literals + +from unittest import skipIf + +import django +from django.test import TestCase +from django.db.models import Prefetch + +from tests.models import InheritanceManagerTestParent, InheritanceManagerTestChild1 + + +class InheritanceIterableTest(TestCase): + @skipIf(django.VERSION[:2] == (1, 10), "Django 1.10 expects ModelIterable not a subclass of it") + def test_prefetch(self): + qs = InheritanceManagerTestChild1.objects.all().prefetch_related( + Prefetch( + 'normal_field', + queryset=InheritanceManagerTestParent.objects.all(), + to_attr='normal_field_prefetched' + ) + ) + self.assertEquals(qs.count(), 0)