Document the remaining PageQuerySet methods

This commit is contained in:
Matt Westcott 2015-11-30 22:16:08 +00:00
parent 95d9a27c7b
commit c35ae95d9b
2 changed files with 25 additions and 2 deletions

View file

@ -69,6 +69,8 @@ Reference
# Add 'my_page' to the menu
my_page.show_in_menus = True
.. automethod:: not_in_menu
.. automethod:: page
Example:
@ -120,6 +122,8 @@ Reference
# Alternative way
sections = homepage.get_children()
.. automethod:: not_child_of
.. automethod:: ancestor_of
Example:
@ -141,6 +145,10 @@ Reference
# Get the other sections
other_sections = Page.objects.not_ancestor_of(current_page).child_of(homepage)
.. automethod:: parent_of
.. automethod:: not_parent_of
.. automethod:: sibling_of
Example:
@ -153,6 +161,8 @@ Reference
# Alternative way
siblings = current_page.get_siblings()
.. automethod:: not_sibling_of
.. automethod:: public
See: :ref:`private_pages`
@ -168,6 +178,8 @@ Reference
# Find all the pages that are viewable by the public
all_pages = Page.objects.live().public()
.. automethod:: not_public
.. automethod:: search
See: :ref:`wagtailsearch_searching_pages`
@ -188,6 +200,8 @@ Reference
# Find all pages that are of type AbstractEmailForm, or a descendant of it
form_pages = Page.objects.type(AbstractEmailForm)
.. automethod:: not_type
.. automethod:: unpublish
Example:

View file

@ -85,9 +85,15 @@ class TreeQuerySet(MP_NodeQuerySet):
return Q(path=self.model._get_parent_path_from_path(other.path))
def parent_of(self, other):
"""
This filters the QuerySet to only contain the parent of the specified page.
"""
return self.filter(self.parent_of_q(other))
def not_parent_of(self, other):
"""
This filters the QuerySet to exclude the parent of the specified page.
"""
return self.exclude(self.parent_of_q(other))
def sibling_of_q(self, other, inclusive=True):
@ -114,7 +120,7 @@ class TreeQuerySet(MP_NodeQuerySet):
By default, inclusive is set to True so it will exclude the specified page from the results.
If inclusive is set to False, the page will be included the results.
If inclusive is set to False, the page will be included in the results.
"""
return self.exclude(self.sibling_of_q(other, inclusive))
@ -145,6 +151,9 @@ class PageQuerySet(SearchableQuerySetMixin, TreeQuerySet):
return self.filter(self.in_menu_q())
def not_in_menu(self):
"""
This filters the QuerySet to only contain pages that are not in the menus.
"""
return self.exclude(self.in_menu_q())
def page_q(self, other):
@ -204,7 +213,7 @@ class PageQuerySet(SearchableQuerySetMixin, TreeQuerySet):
def unpublish(self):
"""
This unpublishes all pages in the QuerySet
This unpublishes all pages in the QuerySet.
"""
self.update(live=False, has_unpublished_changes=True)