Add PageQuerySet.ever_live() and PageQueryset.never_live() filters

pull/7774/head
Andy Babic 2021-12-11 13:15:00 +00:00 zatwierdzone przez Andy Babic
rodzic b062c22331
commit d8c2e33505
2 zmienionych plików z 33 dodań i 0 usunięć

Wyświetl plik

@ -50,6 +50,22 @@ Reference
unpublished_pages = Page.objects.not_live()
.. automethod:: ever_live
Example:
.. code-block:: python
published_or_once_published_pages = Page.objects.ever_live()
.. automethod:: never_live
Example:
.. code-block:: python
never_published_pages = Page.objects.never_live()
.. automethod:: in_menu
Example:

Wyświetl plik

@ -164,6 +164,23 @@ class PageQuerySet(SearchableQuerySetMixin, TreeQuerySet):
"""
return self.exclude(self.live_q())
def ever_live_q(self):
return Q(Q(last_published_at__isnull=False) | Q(live=True))
def ever_live(self):
"""
This filters the QuerySet to only contain pages that have at some
point in their history been published.
"""
return self.filter(self.ever_live_q())
def never_live(self):
"""
This filters the QuerySet to only contain pages that have never
been published before (have always been drafts).
"""
return self.exclude(self.ever_live_q())
def in_menu_q(self):
return Q(show_in_menus=True)