我有这个模型:
class User(ndb.Model):
firstname = ndb.StringProperty(required = True)
lastname = ndb.StringProperty(required = True)
email = ndb.StringProperty(required = True)
birthday = ndb.DateProperty(required = True)
@classmethod
def to_message(self):
return UserMessage(firstname = self.firstname,
lastname = self.lastname,
email = self.email,
birthday_day = self.birthday.day)
其中 UserMessage 是一个 protoRPC 对象。并想要这样的东西:
user = User.query(User.email == 'john@example.com').get()
user_message = user.to_message()