我在设计生产管理软件。我的应用程序允许我的用户执行以下操作:
我在为时间表设计数据结构时遇到问题。你知道吗
我现在有以下内容:
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,如果这有区别的话。你知道吗
数据库中有一个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
相关问题 更多 >
编程相关推荐