小编Mar*_*rty的帖子

在 Marshallow / SQLAlchemy 架构上展平数据

我在如何从端点之一取回数据方面遇到了一些问题 - 特别是使用 Marshmallow 和 SQLAlchemy。

我在鸡尾酒和配料之间有多对多的关系,但我在关系表 ings_in_cocktail 上也有不仅仅是外键的更多数据,例如ounces.When I GET /cocktails/,它返回如下内容:

{
  "cocktails": [
    {
      "glass": "rocks",
      "ingredients": [
        {
          "ingredient": {
            "ing_type": "liquor",
            "id": 1,
            "name": "gin"
          },
          "ounces": 20
        }
      ],
      "finish": "stirred",
      "id": 1,
      "name": "gin and tonic"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

我想做的是将财产的传播ouncesingredient字典结合起来。

我希望数据如下所示:

{
  "cocktails": [
    {
      "glass": "rocks",
      "ingredients": [
        {
          "ing_type": "liquor",
          "id": 1,
          "name": "gin",
          "ounces": 20
        }
      ],
      "finish": "stirred",
      "id": 1,
      "name": "gin and …
Run Code Online (Sandbox Code Playgroud)

python sqlalchemy flask marshmallow

1
推荐指数
1
解决办法
2423
查看次数

标签 统计

flask ×1

marshmallow ×1

python ×1

sqlalchemy ×1