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

怎甘沉沦 提交于 2019-12-25 04:43:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!