Merge branch 'master' into travis-tox
commit
6ec29b9e5e
|
|
@ -92,7 +92,6 @@ matrix:
|
||||||
env: TOXENV="djangodev"
|
env: TOXENV="djangodev"
|
||||||
|
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- env: TOXENV="django111"
|
|
||||||
- env: TOXENV="djangodev"
|
- env: TOXENV="djangodev"
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
.. image:: https://travis-ci.org/django-polymorphic/django-polymorphic.png?branch=master
|
.. image:: https://travis-ci.org/django-polymorphic/django-polymorphic.svg?branch=master
|
||||||
:target: http://travis-ci.org/django-polymorphic/django-polymorphic
|
:target: http://travis-ci.org/django-polymorphic/django-polymorphic
|
||||||
.. image:: https://img.shields.io/pypi/v/django-polymorphic.svg
|
.. image:: https://img.shields.io/pypi/v/django-polymorphic.svg
|
||||||
:target: https://pypi.python.org/pypi/django-polymorphic/
|
:target: https://pypi.python.org/pypi/django-polymorphic/
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,25 @@ except ImportError:
|
||||||
Polymorphic_QuerySet_objects_per_request = CHUNK_SIZE
|
Polymorphic_QuerySet_objects_per_request = CHUNK_SIZE
|
||||||
|
|
||||||
|
|
||||||
|
if django.VERSION >= (1, 9):
|
||||||
|
# We ignore this on django < 1.9, as ModelIterable didn't yet exist.
|
||||||
|
from django.db.models.query import ModelIterable
|
||||||
|
|
||||||
|
|
||||||
|
class PolymorphicModelIterable(ModelIterable):
|
||||||
|
def __iter__(self):
|
||||||
|
base_iter = super(PolymorphicModelIterable, self).__iter__()
|
||||||
|
|
||||||
|
if self.queryset.polymorphic_disabled:
|
||||||
|
for o in base_iter:
|
||||||
|
yield o
|
||||||
|
return
|
||||||
|
|
||||||
|
real_instances = self.queryset._get_real_instances(base_iter)
|
||||||
|
for obj in real_instances:
|
||||||
|
yield obj
|
||||||
|
|
||||||
|
|
||||||
def transmogrify(cls, obj):
|
def transmogrify(cls, obj):
|
||||||
"""
|
"""
|
||||||
Upcast a class to a different type without asking questions.
|
Upcast a class to a different type without asking questions.
|
||||||
|
|
@ -72,6 +91,9 @@ class PolymorphicQuerySet(QuerySet):
|
||||||
# to that queryset as well).
|
# to that queryset as well).
|
||||||
self.polymorphic_deferred_loading = (set([]), True)
|
self.polymorphic_deferred_loading = (set([]), True)
|
||||||
super(PolymorphicQuerySet, self).__init__(*args, **kwargs)
|
super(PolymorphicQuerySet, self).__init__(*args, **kwargs)
|
||||||
|
if django.VERSION >= (1, 9):
|
||||||
|
# On django < 1.9 we override the iterator() method instead
|
||||||
|
self._iterable_class = PolymorphicModelIterable
|
||||||
|
|
||||||
def _clone(self, *args, **kwargs):
|
def _clone(self, *args, **kwargs):
|
||||||
# Django's _clone only copies its own variables, so we need to copy ours here
|
# Django's _clone only copies its own variables, so we need to copy ours here
|
||||||
|
|
@ -407,6 +429,8 @@ class PolymorphicQuerySet(QuerySet):
|
||||||
|
|
||||||
return resultlist
|
return resultlist
|
||||||
|
|
||||||
|
if django.VERSION < (1, 9):
|
||||||
|
# On django 1.9+, we can define self._iterator_class instead of iterator()
|
||||||
def iterator(self):
|
def iterator(self):
|
||||||
"""
|
"""
|
||||||
This function is used by Django for all object retrieval.
|
This function is used by Django for all object retrieval.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue