Merge pull request #279 from hanleyhansen/inheritance-iterable

Update InheritanceIterable to inherit from ModelIterable instead of BaseIterable
This commit is contained in:
Hanley Hansen 2018-05-02 14:14:22 -04:00 committed by GitHub
commit 18dfb6b2cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 2 deletions

View file

@ -15,6 +15,7 @@ Facundo Gaich <facugaich@gmail.com>
Felipe Prenholato <philipe.rp@gmail.com>
Filipe Ximenes <filipeximenes@gmail.com>
Gregor Müllegger <gregor@muellegger.de>
Hanley Hansen <hanleyhansen@gmail.com>
ivirabyan
James Oakley <jfunk@funktronics.ca>
Jannis Leidel <jannis@leidel.info>

View file

@ -3,6 +3,8 @@ CHANGES
master (unreleased)
-------------------
* Update InheritanceIterable to inherit from
ModelIterable instead of BaseIterable, fixes GH-277.
3.1.1 (2017.12.17)
------------------

View file

@ -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)

View file

@ -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)