简体   繁体   中英

How do I get the value of a StringProperty in Python for Google App Engine?

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?

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 !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM