2
爲什麼既不是下面的例子工作?如何獲得定製ndb.Model方法的工作(GAE和Python)
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
所以基本上我希望能夠調用get_person
法last_name
和max_height
,並使其返回一個人(假設只有一個比賽)。我如何實現這一目標?
調用的類/對象有下面幾行:
my_person = Person.get_person('Doe',7)
if my_person.first_name is None:
my_person.first_name = 'John'
但是代碼失敗說my_person
沒有屬性first_name
(或任何其他屬性我試試)。