From 626fdcac89c2ebd898a6ad4f33d2446e9f63d222 Mon Sep 17 00:00:00 2001 From: Rabbit <9531183+rabbit_test@user.noreply.gitee.com> Date: Thu, 9 Sep 2021 02:27:30 +0000 Subject: [PATCH] =?UTF-8?q?update=20applications/view/admin/user.py.=20?= =?UTF-8?q?=E7=AE=80=E5=8C=96=E7=94=A8=E6=88=B7=E5=85=B3=E8=81=94=E6=9D=83?= =?UTF-8?q?=E9=99=90=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/view/admin/user.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/applications/view/admin/user.py b/applications/view/admin/user.py index f2556ba..2a6d9e0 100644 --- a/applications/view/admin/user.py +++ b/applications/view/admin/user.py @@ -119,15 +119,10 @@ def update(): role_ids = a.split(',') User.query.filter_by(id=id).update({'username': username, 'realname': real_name, 'dept_id': dept_id}) u = User.query.filter_by(id=id).first() - roles_id = [] - for role in u.role: - roles_id.append(role.id) - roles = Role.query.filter(Role.id.in_(roles_id)).all() - for r in roles: - u.role.remove(r) + roles = Role.query.filter(Role.id.in_(role_ids)).all() - for r in roles: - u.role.append(r) + u.role = roles + db.session.commit() return success_api(msg="更新成功") -- Gitee