我有以下两个类,我app.models
正在使用 wagtail API 将数据作为 json
class AuthorMeta(Page):
author=models.OneToOneField(User)
city = models.ForeignKey('Cities', related_name='related_author')
class Cities(Page):
name = models.CharField(max_length=30)
因此,当我尝试时/api/v1/pages/?type=dashboard.AuthorMeta&fields=title,city
,它会返回以下数据:
{
"meta": {
"total_count": 1
},
"pages": [
{
"id": 11,
"meta": {
"type": "dashboard.AuthorMeta",
"detail_url": "http://localhost:8000/api/v1/pages/11/"
},
"title": "Suneet Choudhary",
"city": {
"id": 10,
"meta": {
"type": "dashboard.Cities",
"detail_url": "http://localhost:8000/api/v1/pages/10/"
}
}
}
]
}
在城市字段中,它返回城市的id
和meta
。如何在不进行额外查询的情况下在此处获取响应中的城市名称?:/
我在文档中找不到任何解决方案。我错过了什么吗?