如何将StructuredData实体添加到ndb.模型使用循环?

2024-03-29 13:05:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我有个问题。你知道吗

我有两个ndb.模型具有这些属性。你知道吗

class DatesPrices(ndb.Model):
    startDate  = ndb.DateProperty
    endDate    = ndb.DateProperty


class Hotel(ndb.Model):
    datesAndPrices     = ndb.StructuredProperty(DatesPrices, repeated=True)

因此,我需要创建一个新的酒店实体,并在其StructuredProperty属性中放置几个“datesAndPrices”模型(可以是任意数量)。你知道吗

那么我怎样才能通过“for循环”把它放进去呢?你知道吗

hotel = Hotel()

for x in range(0, someRandomCounter):
    hotel.datesAndPrices.append(DatesPrices(startDate  ='',
                                            startDate  =''));
hotel.put()
????

这是正确的吗?我能加上它吗?或者?你知道吗

我会感激任何帮助!谢谢。你知道吗


Tags: 模型formodel属性hotelrepeatedclassndb