Fairly new to Wagtail - I'm currently creating a Wagtail API for my React app. Have installed successfully and am getting a json output, but not getting a url for images that are uploaded in the Wagtail admin panel. I have searched online, but not having much joy.
This is the basic home page model I have created
class BarsHomePage(Previewable, Themable, Page):
bars_site_homepage_test = models.CharField(max_length=255, blank=True)
feed_image = models.ForeignKey(
'DemoImage',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
api_fields = ['bars_site_homepage_test','feed_image']
class DemoImage(Image):
@property
def fullwidth_url(self):
return generate_image_url(self, 'width-800')
@property
def halfwidth_url(self):
return generate_image_url(self, 'width-400')
api_fields = (
'fullwidth_url',
'halfwidth_url',
)
class Meta:
proxy = True
Json output
{
"id": 504,
"meta": {
"type": "wagtailimages.Image",
"detail_url": "http://www.lv.local/api/v1/images/504/"
},
"title": "Lighthouse.jpg",
"tags": [],
"width": 1365,
"height": 2048
}
Thanks