Why is neither of the following examples working?
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
The other example replaces Person with 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
So basically I want to be able to call the get_person method with last_name and max_height and have it return a person (assume there is only one match). How do I accomplish that?
The calling class/object has the following lines:
my_person = Person.get_person('Doe',7)
if my_person.first_name is None:
my_person.first_name = 'John'
But the code fails saying my_person does not have attribute first_name (or whatever other attribute I try).
The following works: