0
我有一個傳統的谷歌應用程序引擎代碼,這是其在Python是正確的方式下獲得唯一的ID在App Engine數據存儲
以下實體類class AffiliateParent(db.Model):
name = db.StringProperty(required = True)
class Affiliate(db.Model):
email = db.StringProperty(required = True)
point_gain = db.IntegerProperty()
point_used = db.IntegerProperty()
#feature_upgrade = db.ListProperty(str)
modified_time = db.DateTimeProperty(auto_now = True)
我想知道,是下面的正確的方式來生成唯一的ID?它們在Affiliate
表中保證是唯一的嗎?
affiliate_parent_key = AffiliateParent.all(keys_only=True).filter('name =', 'yancheng').get();
affiliate_parent = db.get(affiliate_parent_key);
# check whether affiliate exist, if not create one
affiliate_parent = db.get(affiliate_parent_key);
q = Affiliate.all()
q.ancestor(affiliate_parent)
q.filter('email =', email)
affiliate = q.get()
if not affiliate:
affiliate = Affiliate(
email = email,
point_gain = 0,
point_used = 0,
parent = affiliate_parent
)
affiliate.put()
# 4503602445942784
# is this unique?
unique_id = affiliate.key().id()
看起來像它的實體組中生成唯一的ID,所以它只能在實體d組的獨特由'affiliate_parent'定義,對吧? – tx802
是...只在實體組內唯一 –