Fix .non_polymorphic(), returns a copy of the queryset

Just like .filter() and such do.
This commit is contained in:
Diederik van der Boor
2013-09-19 19:36:05 +02:00
parent 61e9a8050a
commit e1093ff1fb
2 changed files with 11 additions and 4 deletions
+5 -4
View File
@@ -67,8 +67,9 @@ class PolymorphicQuerySet(QuerySet):
"""switch off polymorphic behaviour for this query.
When the queryset is evaluated, only objects of the type of the
base class used for this query are returned."""
self.polymorphic_disabled = True
return self
qs = self._clone()
qs.polymorphic_disabled = True
return qs
def instance_of(self, *args):
"""Filter the queryset to only include the classes in args (and their subclasses).
@@ -109,8 +110,8 @@ class PolymorphicQuerySet(QuerySet):
"""translate the polymorphic field paths in the kwargs, then call vanilla aggregate.
We need no polymorphic object retrieval for aggregate => switch it off."""
self._process_aggregate_args(args, kwargs)
self.polymorphic_disabled = True
return super(PolymorphicQuerySet, self).aggregate(*args, **kwargs)
qs = self.non_polymorphic()
return super(PolymorphicQuerySet, qs).aggregate(*args, **kwargs)
# Since django_polymorphic 'V1.0 beta2', extra() always returns polymorphic results.^
# The resulting objects are required to have a unique primary key within the result set