mirror of
https://github.com/Hopiu/django-model-utils.git
synced 2026-03-16 20:00:23 +00:00
make InheritanceIterable inherit from ModelIterable instead of BaseIterable
This commit is contained in:
parent
343d459406
commit
0a809df4da
3 changed files with 25 additions and 2 deletions
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
22
tests/test_inheritance_iterable.py
Normal file
22
tests/test_inheritance_iterable.py
Normal 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)
|
||||
Loading…
Reference in a new issue