Merge branch 'pagequeryset-type-method-improvement' of https://github.com/kaedroho/wagtail into kaedroho-pagequeryset-type-method-improvement

This commit is contained in:
Matt Westcott 2014-10-01 17:22:36 +01:00
commit 85607665e5

View file

@ -1,4 +1,4 @@
from django.db.models import Q
from django.db.models import Q, get_models
from django.contrib.contenttypes.models import ContentType
from treebeard.mp_tree import MP_NodeQuerySet
@ -152,9 +152,13 @@ class PageQuerySet(MP_NodeQuerySet):
"""
return self.exclude(self.sibling_of_q(other, inclusive))
def type_q(self, model):
content_type = ContentType.objects.get_for_model(model)
return Q(content_type=content_type)
def type_q(self, klass):
content_types = ContentType.objects.get_for_models(*[
model for model in get_models()
if issubclass(model, klass)
]).values()
return Q(content_type__in=content_types)
def type(self, model):
"""