4

次の 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/"
                }
            }
        }
    ]
}

都市フィールドでは、都市のidandmetaを返します。追加のクエリを作成せずに、ここの応答で都市の名前を取得するにはどうすればよいですか? :/

Documentationに解決策が見つかりませんでした。何か不足していますか?

4

2 に答える 2