mirror of
https://github.com/Hopiu/django-model-utils.git
synced 2026-03-17 04:10:24 +00:00
Fix missing subclasses and annotated in cloned InheritanceQueryset (#335)
Bug only occurs in django > 2
This commit is contained in:
parent
2cb773372d
commit
326bd7bc02
2 changed files with 9 additions and 1 deletions
|
|
@ -97,7 +97,11 @@ class InheritanceQuerySetMixin(object):
|
|||
|
||||
def _clone(self, klass=None, setup=False, **kwargs):
|
||||
if django.VERSION >= (2, 0):
|
||||
return super(InheritanceQuerySetMixin, self)._clone()
|
||||
qs = super(InheritanceQuerySetMixin, self)._clone()
|
||||
for name in ['subclasses', '_annotated']:
|
||||
if hasattr(self, name):
|
||||
setattr(qs, name, getattr(self, name))
|
||||
return qs
|
||||
|
||||
for name in ['subclasses', '_annotated']:
|
||||
if hasattr(self, name):
|
||||
|
|
|
|||
|
|
@ -460,3 +460,7 @@ class InheritanceManagerRelatedTests(InheritanceManagerTests):
|
|||
qs = InheritanceManagerTestParent.objects.annotate(
|
||||
test_count=models.Count('id')).select_subclasses()
|
||||
self.assertEqual(qs.get(id=self.child1.id).test_count, 1)
|
||||
|
||||
def test_clone_when_inheritance_queryset_selects_subclasses_should_clone_them_too(self):
|
||||
qs = InheritanceManagerTestParent.objects.select_subclasses()
|
||||
self.assertEqual(qs.subclasses, qs._clone().subclasses)
|
||||
|
|
|
|||
Loading…
Reference in a new issue