diff --git a/CHANGELOG.txt b/CHANGELOG.txt index a58c03d981..00f919cc9e 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -5,6 +5,7 @@ Changelog ~~~~~~~~~~~~~~~~ * Added support for Python 3.7 (Matt Westcott) + * Fix: Query objects returned from `PageQuerySet.type_q` can now be merged with `|` (Brady Moe) 2.3 LTS (23.10.2018) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index ae8e7f031e..7b7423ab4d 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -322,6 +322,7 @@ Contributors * Meteor0id * Naa Marteki Reed * Jorge Barata +* Brady Moe Translators =========== diff --git a/docs/releases/2.4.rst b/docs/releases/2.4.rst index 1c287acc52..6ddea4594b 100644 --- a/docs/releases/2.4.rst +++ b/docs/releases/2.4.rst @@ -20,6 +20,8 @@ Other features Bug fixes ~~~~~~~~~ + * Query objects returned from ``PageQuerySet.type_q`` can now be merged with ``|`` (Brady Moe) + Upgrade considerations ====================== diff --git a/wagtail/core/query.py b/wagtail/core/query.py index 6e984cb01b..add03e9e1a 100644 --- a/wagtail/core/query.py +++ b/wagtail/core/query.py @@ -178,7 +178,7 @@ class PageQuerySet(SearchableQuerySetMixin, TreeQuerySet): if issubclass(model, klass) ]).values() - return Q(content_type__in=content_types) + return Q(content_type__in=list(content_types)) def type(self, model): """ diff --git a/wagtail/core/tests/test_page_queryset.py b/wagtail/core/tests/test_page_queryset.py index c4f92e87ad..019fc34404 100644 --- a/wagtail/core/tests/test_page_queryset.py +++ b/wagtail/core/tests/test_page_queryset.py @@ -1,4 +1,5 @@ from django.contrib.contenttypes.models import ContentType +from django.db.models import Q from django.test import TestCase from wagtail.core.models import Page, PageViewRestriction, Site @@ -397,6 +398,14 @@ class TestPageQuerySet(TestCase): # Check that the event is in the results self.assertTrue(pages.filter(id=event.id).exists()) + def test_merge_queries(self): + type_q = Page.objects.type_q(EventPage) + query = Q() + + query |= type_q + + self.assertTrue(Page.objects.filter(query).exists()) + class TestPageQueryInSite(TestCase): fixtures = ['test.json']