0
votes

I got index pages that shows subpages as items. I added a property and a serializer.field to return the json data in my page. So far so good. But child pages can be 100+ so I added a paginator on my the queryset and and a filter for some tags. My question is that I want now to add a query to so I can call page 1, 2 etc... /somepage/?page=1&tag=bikes When I run pages/find/html_url=... it does not allow the params. How should I go about this “simple” task with Wagtail API?

class ChildrenSerializer(Field):
   def to_representation(self, value):
       retval = []
       for item in value:
           retval.append{....}
   return retval

class SomeIndexPage(Page):
   ...
   @property
   def children(self):
      *#how to get request to check params?*
      qs = self.get_children().live()
      paginator = Paginator(qs, 12)
      page_number = 1
      ...

    api_field = [
      ....
      APIFields(children, serializer=ChildrenSerializer()),
      ...
     ]

What I want to do is get in the def children a page number so I can query for new page numbers. So if somebody visits the URL /someindexpage/?page=1 it will return the queryset for page 1

The problem is when I request via Nuxt/Axios the this will not work. The page params are not accepted and the request is not available in the 'def children():' So I can't change page numbering for this.

I look up the page via /pages/find/html_url=/someindexpage/?page=1&tag=sometag

What is the best way to do this? Except creating a seperate serializer + a view and adding custom url to pull this.

I don't want to use the url query/filter methods that wagtail offers. https://docs.wagtail.io/en/stable/advanced_topics/api/v2/usage.html#filtering

1

1 Answers

0
votes

I guess its a easy solution. Your need to access the request in ChildrenSerializer. There you can do the query and all you need for the pagination

self.context['request']