【问题标题】:Structuring model class in appengine (since tuple is NOT available)在 appengine 中构建模型类(因为元组不可用)
【发布时间】:2014-07-25 19:55:43
【问题描述】:

我正在设计用于生产管理的软件。我的应用允许我的用户执行以下操作:

  1. 用户可以创建一个“时间表”。时间表指定需要在特定日期准备好哪些类型的蔬菜产品。
  2. 每种蔬菜都有不同的繁殖、移栽和收获时间。
  3. 我的软件逆向运行,并确定在哪个日期需要做什么等。

我在为 Schedule 设计数据结构时遇到问题。

我现在有以下内容:

class Produce(db.Model):
  crop = db.StringProperty(required=True)
  duration_sow = db.IntegerProperty()
  duration_transplant = db.IntegerProperty()
  duration_storage = db.IntegerProperty()

一个时间表在 JSON 中看起来像这样:

a_schedule = { 
  "crops": [ {"produce": Key(123), "quantity", 15}, {"produce": Key(234), "quantity", 16} ], 
  "created_by": ....
}

由于 Appengine 数据存储不支持元组,我不确定如何在模型中存储“crops”属性。

选项 1

我考虑过使用两个数组,

crops_key = [ Key(123), Key(234), .. ]
quantity = [ 15, 16, ... ]

但随后删除和修改可能会有点棘手。这行得通,但我经常遇到这种模式,我只想看看那里的专家有什么建议。

如果有什么不同,我正在使用 python。

【问题讨论】:

    标签: python google-app-engine database-design schema


    【解决方案1】:

    db 中有一个 ListProperty。

    https://developers.google.com/appengine/docs/python/datastore/typesandpropertyclasses#ListProperty

    这允许您存储多个密钥。 我在一个基于 db 的旧项目中保持两个列表属性同步。

    我注意到您正在使用 db,如果您没有重要的代码库,请考虑迁移到 ndb。 ndb 有更好的模型来存储这些数据。阅读 ndb 中的 StructuredProperties。 https://developers.google.com/appengine/docs/python/ndb/properties

    【讨论】:

    • 是的,我现在正在阅读 NDB。我很喜欢 StructuredProperties
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-05
    • 1970-01-01
    • 2016-07-23
    • 1970-01-01
    相关资源
    最近更新 更多