user47376
user47376

Reputation: 2273

google app engine python: how to extend ndb User class

I'm using google cloud endpoints and want to be able to extend the User class so that a call to get_current_user would return an AppUser object with my own extra properties.

class AppUser(--?--): # what should i put here
    gcm = ndb.StringProperty()

    def send_notification(self):
         # do something with gcm ...
         pass

how can I implement such a thing ? and is there a better way ?

Upvotes: 0

Views: 375

Answers (1)

Jaime Gomez
Jaime Gomez

Reputation: 7067

It's not supported officially, and I wouldn't recommend messing with it; there's a better way, just add a new Model and link it via the user_id, then you can do whatever you want with it.

class Preferences(ndb.Model):
    gcm = ndb.StringProperty()

user = users.get_current_user()
Preferences(
    gcm='',
    id=user.user_id(),
).put()
prefs = Preferences.get_by_id(user.user_id())

Upvotes: 2

Related Questions