Question

I have this model:

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)

Where UserMessage is a protoRPC object. And want something like this:

user = User.query(User.email == 'john@example.com').get()
user_message = user.to_message()
Was it helpful?

Solution

You can't use a class method here.

There is no self in a classmethod , by convention it is cls and you are passed the class not an instance. to_message should be a normal method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top