(WAGTAIL) How to add a button, or something similar, items per page to a model listing in the wagtail administrative area?

29 views Asked by At

I'm trying to add an items button per page in the wagtail administrative area, but I didn't find anything in the documentation. Is there any way to customize and create a button to choose the number of items per page? enter image description here

1

There are 1 answers

0
Rich - enzedonline On

I'm not sure about the button, but you can set the number of items per page as a class attribute in the viewset.

class SomeViewSet(SnippetViewSet):
    model = SomeModel
    list_per_page = 50
    ....

That gets picked up in ModelViewSet:

def get_index_view_kwargs(self, **kwargs):
    return {
        ....
        "paginate_by": self.list_per_page,
        ....
    }

@property
def index_view(self):
    return self.construct_view(
        self.index_view_class, **self.get_index_view_kwargs()
    )

@property
def index_results_view(self):
    return self.construct_view(
        self.index_view_class, **self.get_index_view_kwargs(), results_only=True
    )

I'd imagine you need to write custom index/index results templates: https://docs.wagtail.org/en/stable/extending/generic_views.html#modelviewset-templates

This hook could also be useful for you: https://docs.wagtail.org/en/stable/reference/hooks.html#register-snippet-listing-buttons