【发布时间】:2017-06-16 17:18:09
【问题描述】:
对 Wagtail 相当陌生 - 我目前正在为我的 React 应用程序创建一个 Wagtail API。已成功安装并获得 json 输出,但未获得 Wagtail 管理面板中上传的图像的 url。我在网上搜索过,但没有太多的快乐。
这是我创建的基本主页模型
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 输出
{
"id": 504,
"meta": {
"type": "wagtailimages.Image",
"detail_url": "http://www.lv.local/api/v1/images/504/"
},
"title": "Lighthouse.jpg",
"tags": [],
"width": 1365,
"height": 2048
}
谢谢
【问题讨论】:
-
能否请您展示您的 DemoImage 模型和 json 输出?
-
已在上面进行了编辑 - 请原谅格式错误......