How could I recognize private pages and public pages from QuerySets of Wagtail page?

Viewed 332

when I make a API from wagtail, I have get QuerySets(contain private pages and public pages), then how could i recognize the private pages and public pages? the database tables don't have on filed to recognize it. I know how to get private QuerySets and public QuerySets, use case like below:

Page.objects.filter().all().public().live() Page.objects.filter().all().not_public().live()

is there any filed i can use,like page.private to get this attribute?

1 Answers

The page model has a get_view_restrictions() method, which returns a queryset of restrictions that apply to the page; if this is empty, the page is public.

is_private = page.get_view_restrictions().exists()
Related