Skip to content

Prepopulate sort_order for existing models/pages #28

Description

@andre-fuchs

Thanks for this package! It is working great once I solved the following hick-up.
If you add this package to an existing Wagtail site, sort_order will not be populated on already existing pages. Added to list_display in ModelAdmin, you can see that it stays "-" or "0". Only after adding new pages, these "0" change to "1" possibly. Even then all pages with sort_order "0" or "1" cannot be resorted.
A possible solution could be a lookup of all pages with an undefined sort_order and if existant than prepopulate them. You know better then me where to implement this check:

pages = SomePage.objects.live().order_by('sort_order') 
if pages.filter(sort_order__isnull=True).exists() or pages.filter(sort_order=0).exists():
    for i, page in enumerate(pages):
        page.sort_order = i
        page.save()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions