次の 2 つのクラスが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
andmeta
を返します。追加のクエリを作成せずに、ここの応答で都市の名前を取得するにはどうすればよいですか? :/
Documentationに解決策が見つかりませんでした。何か不足していますか?