谷歌应用程序引擎蟒蛇:如何扩展ndb用户类 [英] google app engine python: how to extend ndb User class
本文介绍了谷歌应用程序引擎蟒蛇:如何扩展ndb用户类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用google云端点,希望能够扩展 User
类,以便调用 get_current_user
会用我自己的额外属性返回一个 AppUser
对象。
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 ?
推荐答案
这不是官方支持的,我不会推荐使用它。有一个更好的方法,只需添加一个新的模型
,并通过 user_id
链接它,然后你可以做任何你想做的事情
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())
这篇关于谷歌应用程序引擎蟒蛇:如何扩展ndb用户类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文