diff --git a/wagtail/wagtailcore/models.py b/wagtail/wagtailcore/models.py index c3f949667b..dc03f7914a 100644 --- a/wagtail/wagtailcore/models.py +++ b/wagtail/wagtailcore/models.py @@ -645,11 +645,12 @@ class Page(MP_Node, ClusterableModel, Indexed): def get_siblings(self, inclusive=True): return Page.objects.sibling_of(self, inclusive) - def get_next_siblings(self): - return self.get_siblings().filter(path__gt=self.path).order_by('path') + def get_next_siblings(self, inclusive=False): + return self.get_siblings(inclusive).filter(path__gte=self.path).order_by('path') + + def get_prev_siblings(self, inclusive=False): + return self.get_siblings(inclusive).filter(path__lte=self.path).order_by('-path') - def get_prev_siblings(self): - return self.get_siblings().filter(path__lt=self.path).order_by('-path') def get_navigation_menu_items(): # Get all pages that appear in the navigation menu: ones which have children, diff --git a/wagtail/wagtailcore/tests/test_page_model.py b/wagtail/wagtailcore/tests/test_page_model.py index 2fc6af5ba9..24eabd8667 100644 --- a/wagtail/wagtailcore/tests/test_page_model.py +++ b/wagtail/wagtailcore/tests/test_page_model.py @@ -233,6 +233,15 @@ class TestPrevNextSiblings(TestCase): christmas_event = Page.objects.get(url_path='/home/events/christmas/') self.assertTrue(christmas_event.get_next_siblings().filter(url_path='/home/events/final-event/').exists()) + def test_get_next_siblings_inclusive(self): + christmas_event = Page.objects.get(url_path='/home/events/christmas/') + + # First element must always be the current page + self.assertEqual(christmas_event.get_next_siblings(inclusive=True).first(), christmas_event) + def test_get_prev_siblings(self): final_event = Page.objects.get(url_path='/home/events/final-event/') self.assertTrue(final_event.get_prev_siblings().filter(url_path='/home/events/christmas/').exists()) + + # First element must always be the current page + self.assertEqual(final_event.get_prev_siblings(inclusive=True).first(), final_event)