繁体   English   中英

在新的 Cloud Datastore 模式下实现 ndb.StructuredProperty 的等效性?

[英]Achieving the equivalence of ndb.StructuredProperty in new Cloud Datastore Mode?

在旧的ndb Datastore 中,可以创建StructuredProperty 这要归功于提供的ndb.Model

但是,在新的 Cloud Datastore 中,ndb 不可用。 那么我们如何在新的 Cloud Datastore 中实现与 ndb.StructuredProperty 类似的功能呢?

我有一个 JobApplication 模型,其中包含一个或多个 Education 和 Experience 对象:

class Education:
    def __init__(self, institution):
        institution = self.institution

class Experience:
    def __init__(self, workplace):
        workplace = self.workplace

class JobApplication:
    def __init__(self):
        self.educations = None
        self.experiences = None

    def add_education(self, education):
        self.educations.append(education)

    def add_experience(self, experience):
        self.experiences.append(experience)        


edu_1 = Education('aol')
edu_2 = Education('myspace')

jobapp = JobApplication()
jobapp.add_education(edu_1)
jobapp.add_education(edu_2)

虽然这有点适用于reading实体,但在尝试update实体时变得复杂。 例如,我如何能够在JobApplication对象中更新edu_2

使用旧的 ndb 方法非常简单:

class Education(ndb.Model):
    institution = ndb.StringProperty()

class JobApplication(ndb.Model)
    education = ndb.StructuredProperty(Education, repeated=True)

如何使用新的 Cloud Datastore 实现这一结果?

如评论中所述,您可以在第一代 App Engine 标准运行时以外的环境中使用google-cloud-ndb 因此您可以继续使用 StructuredProperty。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM