gpt4 book ai didi

python - Google App Engine ndb 查询

转载 作者:行者123 更新时间:2023-12-01 05:03:07 25 4
gpt4 key购买 nike

我在 Google Cloud Datastore 中为我的项目创建了一个名为“Event”的实体。该实体有一个由 AppEngine 生成的 ID,后跟两个属性

  • 地点
  • 日期

我正在尝试通过 ID (5629499534213120) 查询该实体,所以,这是我的代码。

    key = 5629499534213120
e = Event.get_by_id(key)
logging.info("Event Location = %s" % e.Location)

e 的值为 NoneType。

代码

   __author__ = 'vinayjoseph'

from google.appengine.ext import ndb
import logging


class Event(ndb.Model):
"""Models an individual event at xxx xxxx """
Date = ndb.DateTimeProperty()
Location = ndb.StringProperty()


def get_meeting_date():
"""gets the next meeting date from the No SQL Schemaless Google Datastore
"""
key = 5629499534213120
e = Event.get_by_id(key)
logging.info("Event Location = %s" % e.Location)

e 是 NoneType

在数据存储中我看到以下内容 https://console.developers.google.com/project/apps~xxxxx/datastore/editentity?key=xxxxx%2FEvent%20id:5629499534213120

screen shot of the entity in the datastore

我怀疑问题可能出在我的 key 上。

当我尝试使用 dev_appserver.py 查询开发中的数据存储时,它可以工作。我对开发使用不同的 key 。

def get_meeting_date():
"""gets the next meeting date from the No SQL Schemaless Google Datastore
"""
#dev
key = 6401356696911872
#prd
#key = 5629499534213120
e = Event.get_by_id(key)
logging.info("Event Location = %s" % e.Location)

enter image description here

最佳答案

好吧,我终于明白了。

我必须对实体本身进行一些更改,才能正确进行过滤。所以新的属性如下所示。 Entity Properties

Python中的代码如下:

__author__ = 'vinayjoseph'

from google.appengine.ext import ndb
import logging
from datetime import datetime

class Event(ndb.Model):
"""Models an individual event at xxx xxx """
Date = ndb.DateTimeProperty()
Location = ndb.StringProperty()
Address = ndb.StringProperty()
Name = ndb.StringProperty()


def get_meeting_date():
"""gets the next meeting date from the No SQL Schemaless Google Datastore
"""
qry = Event.query(Event.Name == 'Next Meeting Location')
for event in qry.fetch(1):
logging.info("Meeting is on %s at %s" % (str(event.Date), event.Address))

它就像一个魅力。查看应用程序引擎中的日志条目

enter image description here

关于python - Google App Engine ndb 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25624831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com