Google App Engine(python):根据自定义字段筛选用户 [英] Google App Engine (python): filter users based on custom fields

查看:355
本文介绍了Google App Engine(python):根据自定义字段筛选用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 webapp2_extras.appengine.auth.models.User 服务,它基本上扩展了 google.appengine.api.users模型 code>。现在,我有我的应用程序注册的自定义用户,他们有很多自定义字段。问题是我想过滤/(多过滤器)所有使用各种自定义字段的用户。例如:
$ b

用户模型有两个字段 is_active activation_key 现在我想过滤这些字段,例如:

pre
$ b act_key ='hw-2j38he63u83hd6hak3FshSqj3TGemn9'
user = users.all()。filter('is_active =',False).filter('activation_key =',act_key).get()
如果用户:
return True
else:
return False

使用自定义字段过滤用户模型的最佳方式是什么?



编辑:

尝试以下内容:

  from webapp2_extras.appengine.auth.models import User 

query = User。 query()。filter('is_active =',False)
打印查询

引发一个错误,如下所示:

pre code $ Traceback最近一次调用最后一个
文件/opt/google_appengine_1.6.4 /谷歌/应用服务引擎/ ext / admin / __ init__.py,第320行,在
exec(compiled_code,globals())
在< module>中的第6行文件< string>
文件lib / ndb / query.py,第968行,在过滤器
中引发TypeError('无法过滤非节点参数;收到%r'%arg)
TypeError:Can not过滤非节点参数;收到'is_active ='


解决方案

webapp2_extras.appengine.auth.models.User 是一个带有创建的Expando模型更新 auth_ids password 属性。除此之外的所有内容或自定义属性都将被存储为不透明的blob,即不会被索引。也就是说,不能查询/筛选它们。



您可以继承 User 模型并添加属性你需要或(更好)创建一个新的模型(比如 Account )。

这是个好习惯在处理数据存储时,尽可能保持模型的小型化,这就是为什么:考虑一个包含数十个属性的模型,每次获取需要获取的实体时,网络是不是一个问题,什么是protobuf解码和Python是不是真的很擅长。


i am using the webapp2_extras.appengine.auth.models.User service which basically extends the google.appengine.api.users model. Now , I have custom users registered with my application and they have a lot of custom fields. The problem is i want to filter / (multi filter) all the users using various custom fields. For example:

the user model has 2 fields is_active and activation_key now i want to filter them using these fields, example:

from google.appengine.api import users

act_key = 'hw-2j38he63u83hd6hak3FshSqj3TGemn9'
user = users.all().filter('is_active =', False).filter('activation_key =', act_key).get()
if user:
  return True
else:
  return False

what are the best possible ways to filter on the user model using custom fields?

Edit:

Also tried the following:

from webapp2_extras.appengine.auth.models import User

query = User.query().filter('is_active =', False)
print query

but this raises an error as follows:

Traceback (most recent call last):
File "/opt/google_appengine_1.6.4/google/appengine/ext/admin/__init__.py", line 320, in post
exec(compiled_code, globals())
File "<string>", line 6, in <module>
File "lib/ndb/query.py", line 968, in filter
raise TypeError('Cannot filter a non-Node argument; received %r' % arg)
TypeError: Cannot filter a non-Node argument; received 'is_active ='

解决方案

webapp2_extras.appengine.auth.models.User is an Expando model with created, updated, auth_ids and password properties. Everything beyond that or custom properties would be stored as an opaque blob, i.e., wouldn't be indexed. That said, one can't query/filter on them.

You could subclass the User model and add properties you need or (which is better) create a new model (say Account).

This is a good habit when dealing with the Datastore to keep your model as small as you can, and this is why: consider a model with dozens of properties, each time you fetch an entity you'd need to fetch them all; network isn't an issue here, what is, is protobuf decoding and Python is not really good at it.

这篇关于Google App Engine(python):根据自定义字段筛选用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆