簡體   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