关于Admin的query
来源:8-4 .访问权限控制
Grant_Lian
2017-09-13
def admin_auth(f): @wraps(f) def decorated_function(*args, **kwargs): admin = Admin.query.join( Role ).filter( Role.id == Admin.role_id, Admin.id == session["admin_id"] ).first() auths = admin.role.auths auths = list(map(lambda v: int(v), auths.split(","))) auth_list = Auth.query.all() urls = [v.url for v in auth_list for val in auths if val == v.id] rule = request.url_rule if rule not in urls: abort(404) return f(*args, **kwargs) return decorated_function 老师, 这个Admin.query.join(Role)就是把所有的role type全部取出来么? 后面这个filter(Role.id == Admin.role_id,Admin.id == session["admin_id"] ).first()有点乱,不是很懂这个逻辑,能解释下么,谢谢老师
写回答
1回答
-
同学,你好,相当于关联查询,关联查询的具体语句如下:
select * from admin left join role on role.id = admin.role_id where admin.id = 会话的session["admin_id"]
022017-09-14
相似问题