torchbox / wagtail-headless-preview

Previews for headless Wagtail setups

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

parent data of a page not supplied if parent is also a concept

wimfeijen opened this issue · comments

Hi,

If we are previewing a concept page with a parent which is also in concept status, page_data['meta']['parent'] is not supplied.

However, in preview mode, I would like to have access to the parent data as well, even if it is a concept. For example:
Screenshot 2023-12-15 at 15 09 16

Hey @wimfeijen,

the example page_preview endpoint from the README uses the Wagtail core PagesAPIViewSet which in turn makes use of PageSerializer for the page model and PageParentField for the parent attribute.

Now, in preview mode, especially when adding a new page, the DRF serializers can't really determine the parent.

You could override the serve_preview method to pass the parent to the preview template and by extension to the preview API endpoint and then have your own serializer that will handle that.

Thanks for the pointer @zerolab , I will look into this when I have time!