1

我目前有点卡住了。我必须使用 pynamodb 创建我们的 dynamodb 模型,这就是我所拥有的(更大模型的一部分,从 DB 中的真实用户导出)

packs = [
  {
   "exos": {
    "4": {
     "start": 1529411739,
     "session": 1529411739,
     "finish": 1529417144
    },
    "5": {
     "start": 1529417192,
     "session": 1529417192
    }
   },
   "id": 10
  },
  {
   "exos": {
    "32": {
     "start": 1529411706,
     "session": 1529411706
    }
   },
   "id": 17
  }
 ]

这是我到目前为止得到的:

class ExercisesMapAttribute(MapAttribute):
    pass


class PackMapAttribute(MapAttribute):
    exos = ExercisesMapAttribute()
    id = NumberAttribute()


class TrainUser(Model):
    class Meta:
        table_name = 'TrainUser'
        region = 'eu-west-1'
    # [...] Other stuff removed for clarity
    packs = ListAttribute(of=PackMapAttribute())

目前我认为我正确地起床,直到"4":"5":......因为它们是练习名称。这个想法是这个结构应该代表一个包列表,然后在一个带有它们的 id 和更多信息的练习列表中......我需要一种方法将它从当前的 db json 映射到我可以与 PynamoDB 一起使用的类. 甚至可能吗?

谢谢!

我已经尝试过DynamicMapAttribute,但我不知道它是否适用于我的配置。我也不知道如何使用自定义属性来克服这个问题。

4

0 回答 0