Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google app engine 如何让自定义ndb.Model方法工作(GAE和Python)_Google App Engine_Model_Python 2.7 - Fatal编程技术网

Google app engine 如何让自定义ndb.Model方法工作(GAE和Python)

Google app engine 如何让自定义ndb.Model方法工作(GAE和Python),google-app-engine,model,python-2.7,Google App Engine,Model,Python 2.7,为什么以下两个例子都不起作用 class Person(ndb.Model): first_name = ndb.StringProperty() last_name = ndb.StringProperty() city = ndb.StringProperty() birth_year = ndb.IntegerProperty() height = ndb.IntegerProperty() @classmethod def get_person(s

为什么以下两个例子都不起作用

class Person(ndb.Model):
   first_name = ndb.StringProperty()
   last_name = ndb.StringProperty()
   city = ndb.StringProperty()
   birth_year = ndb.IntegerProperty()
   height = ndb.IntegerProperty()

  @classmethod
  def get_person(self, _last_name, _max_height):
     a_person = Person.query(
           ndb.AND(
              Person.last_name == _last_name,
              Person. height == _max_height
       ))
      return a_person
另一个示例将
Person
替换为
self

@classmethod
  def get_person(self, _last_name, _max_height):
     a_person = self.query(
           ndb.AND(
              self.last_name == _last_name,
              self. height == _max_height
       ))
      return a_person
因此,基本上我希望能够使用
last\u name
max\u height
调用
get\u person
方法,并让它返回一个person(假设只有一个匹配项)。我如何做到这一点

调用类/对象具有以下行:

my_person = Person.get_person('Doe',7)
if my_person.first_name is None:
   my_person.first_name = 'John'
但是代码没有说明“我的人”没有属性“名字”(或我尝试的任何其他属性)。

以下操作有效:

@classmethod
def get_person(self, _last_name, _max_height):
 a_person = Person.query(
       ndb.AND(
          Person.last_name == _last_name,
          Person. height == _max_height
   ))
  return a_person.get()