changing the default sort order for query sets

175 views
Skip to first unread message

John Jung

unread,
Nov 4, 2016, 3:07:47 PM11/4/16
to Wagtail support
Hello,

I would like to adjust the default result order for a custom page type's QuerySet. To do that, I'm trying to extend the PageManager's get_query_set() function:

from wagtail.wagtailcore.models import PageManager

class StaffPageManager(PageManager):
    def get_query_set(self):
        return (
            super(StaffPageManager, self)
            .get_query_set()
            .order_by('title')
        )

#Then, in my custom page:
class StaffPage(Page):
    ...
    objects = StaffPageManager
    ...

However, when I do this, I get the following error message:

ERRORS:
staff.StaffPage: (wagtailcore.E002) Manager does not inherit from PageManager
    HINT: Ensure that custom Page managers inherit from django.db.models.manager.BasePageManagerFromPageQuerySet

However, I'm not able to inherit from BasePageManagerFromPageQuerySet, because that class doesn't exist.

Can anyone tell what I'm doing wrong here? Any help to get me back on track would be greatly appreciated.

Thanks so much!

Best,
John

Matthew Westcott

unread,
Nov 4, 2016, 4:04:09 PM11/4/16
to wag...@googlegroups.com
Hi John,

The 'objects' line should be:
objects = StaffPageManager()
- note the parentheses at the end. (We previously had this wrong in the docs - it was just fixed in the last week or so...)

I'm sure the hint in the error message used to say something more meaningful than that - perhaps that's something that changed between Django versions. Will investigate...

Cheers,
- Matt

John Jung

unread,
Nov 4, 2016, 4:21:36 PM11/4/16
to Wagtail support
That's excellent, Matthew...thanks for getting me back on track!
Reply all
Reply to author
Forward
0 new messages