问题
How do I get the values of a nbd.Model? I want to return a description that is composed of several of the fields but I can't get it to work. This is my code for my class:
class User(ndb.Model):
name = ndb.StringProperty()
email = ndb.StringProperty()
@classmethod
def get_description(self):
# return "Kobe Bryant (kobe.bryant@lakers.net)"
return self.name + ' (' + self.email + ')'
But name is a StringProperty object and can't be appended to a string. How do I get the value of the StringProperty?
回答1:
Actually, self.name
accessed on an instance of class User
is a string and can be perfectly well appended to any other string. Your obvious mistake is in that classmethod
decorator which makes the method apply to the class when it clearly must apply to a specific instance!
来源:https://stackoverflow.com/questions/27751418/how-do-i-get-the-value-of-a-stringproperty-in-python-for-google-app-engine