How to delete from webapp2_extras.appengine.auth.m

2019-02-14 20:24发布

I'm using webapp2_extras.appengine.auth in my project and it creates 3 tables in datastore: User, UserToken and Unique. All is good and working as it should...

My question is: How can I delete something from Unique?

1条回答
2楼-- · 2019-02-14 21:02

I had trouble finding exactly what to delete, since Unique model doesn't hold references to User. Here's the solution (with reference to docs):

from google.appengine.ext import ndb
from webapp2_extras import auth

class SomeUserHandler():
  def forget_user(self):
    auth = auth.get_auth()
    user_dict = auth.get_user_by_session()
    user = auth.store.user_model.get_by_id(user_dict['user_id'])

    # from webapp2_extras.appengine.auth.models.User
    # http://webapp-improved.appspot.com/_modules/webapp2_extras/appengine/auth/models.html#User
    # 
    # def add_auth_id(self, auth_id):
    #   ...
    #   unique = '%s.auth_id:%s' % (self.__class__.__name__, auth_id)
    #   ...
    Unique.delete_multi( map(lambda s: 'User.auth_id:' + s, user.auth_ids) )
查看更多
登录 后发表回答