Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wagtail admin - default ordering of child pages

Tags:

django

wagtail

In the admin area I have to activate the "Enable ordering of child pages" every time. Is there a way to set this as a permanent option? The main problem is that the listing in the child pages view changes depending on if this is activated or not(if you have changed the ordering), which might be a bit confusing for some.

Potentially one could change the default ordering of the children list to match the manually ordered list somehow?

like image 264
ladrua Avatar asked Oct 29 '22 01:10

ladrua


2 Answers

Ok, as of now. It doesn't seem that this is possible. But it does seem that it respects django models default ordering. https://docs.djangoproject.com/en/2.1/ref/models/options/#ordering

like image 158
ladrua Avatar answered Dec 04 '22 08:12

ladrua


Setting the Meta.ordering on the ChildPage model didn't work for me, but overriding the Parent Page's get_children() method by returning the ordered QuerySet resolved the child page order issue.

class MyRootPage(Page):
    description = models.CharField(max_length=255, blank=True)

    content_panels = Page.content_panels + [FieldPanel("description", classname="full")]

    def get_children(self):
        qs = super().get_children()
        qs = qs.order_by('-last_published_at')
        return qs
like image 23
monkut Avatar answered Dec 04 '22 09:12

monkut