Reputation: 740
I have been trying to follow the following docs
http://docs.wagtail.io/en/v1.6.3/reference/contrib/api/installation.html?highlight=api
for my wagtail 1.6.3 instance.
It tells me to add a field to the api_fields array in classes that extend page.
So I have tried this:
class HomePage(HeaderPage):
body = RichTextField(blank=True)
main_image = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
content_panels = HeaderPage.content_panels + [
FieldPanel('body', classname="full"),
ImageChooserPanel('main_image')
]
test = models.CharField(max_length=20, default="test");
api_fields = ['test', 'body', 'main_image','header_image', 'show_in_menus']
But I am only getting these fields on the detail page and on the /api/v1/pages/ endpoint it only shows the title and meta data field. How can I add more fields that will show on that enpoint
Upvotes: 3
Views: 2352
Reputation: 143
I'm not sure what version this started by according to v2.2.2 you can list all fields by using ?fields=*
example:
http://localhost:8000/api/v2/pages/?type=home.HomePage&fields=*
Just be sure you include the ?type= or else it will not expose the api_fields
http://docs.wagtail.io/en/v2.2.2/advanced_topics/api/v2/usage.html#all-fields
Upvotes: 1
Reputation: 1451
You add fields to the listing endpoint by specifying them in the API URL, e.g.
http://localhost:8000/api/v2/pages/?type=blog.BlogPage&fields=body
See http://docs.wagtail.io/en/v1.7/advanced_topics/api/v2/usage.html#custom-page-fields-in-the-api for more details.
Upvotes: 3