【发布时间】:2016-11-24 14:16:07
【问题描述】:
我正在使用 web2py,并且正在尝试为 auth_user 构建一个字段,该字段应该被验证为某个组的成员。所以,在 models/db.py 我添加了一个字段,告诉谁是用户的经理:
auth.settings.extra_fields['auth_user']=[Field('manager', 'reference auth_user')]
然后我设置了db.auth_user、db.auth_group 和db.auth_membership 以包含属于组“经理”的用户
我现在想要实现的是验证用户输入,以便auth_user 的“经理”字段只能包含“经理”组中的用户。我经历了很多变化,以下可能在我看来最接近理论上的意义:
group_id = auth.id_group('managers')
all_users_in_group = db(db.auth_membership.group_id==group_id)._select(db.auth_membership.user_id)
db.auth_user.auditor.requires = IS_IN_DB(db, db(~db.auth_user.id.belongs(all_users_in_group)).select(db.auth_user.id))
但即使这样也失败了
<type 'exceptions.AttributeError'>('Table' object has no attribute 'managers')
我的问题的完美解决方案是在下拉菜单中显示的不是auth_user.id,而是auth_user.first_name 与auth_user.last_name 连接。
【问题讨论】: