mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-12 01:03:11 +00:00
Merge branch 'pagequeryset-type-method-improvement' of https://github.com/kaedroho/wagtail into kaedroho-pagequeryset-type-method-improvement
This commit is contained in:
commit
85607665e5
1 changed files with 8 additions and 4 deletions
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue