In the Wagtail documentation there is a section about removing some fields from the API (http://docs.wagtail.io/en/v2.2.1/advanced_topics/api/v2/usage.html#removing-all-default-fields) by using URL query part ?fields=_,title
. But this is done from the API consumer perspective. What can I do to exclude some fields on the server side, so no matter what the user types in the URL query part he won't be able to get some fields. I know how to exclude the fields I've added, this is done simply by removing them api_fields
list. But there are some 'core' fields such as meta
, id
. How do I exclude those?
3
votes
1 Answers
0
votes
You can register your pages' api endpoint with a custom viewset instead of using the default PageAPIViewSet.
For example, if you want to return only title
field for your pages:
from wagtail.api.v2.views import PagesAPIViewSet, PageSerializer
class MyCustomPagesAPIViewSet(PagesAPIViewSet):
base_serializer_class = PageSerializer
body_fields = [
'title',
]
meta_fields = [
'parent',
]
api_router.register_endpoint('pages', MyCustomPagesAPIViewSet)