简体   繁体   中英

django user_passes_test decorator is_superuser

Initially i was restricting the permission for all user with the help of is_superuser flag,and i used @user_passes_test(lambda u: u.is_superuser) decorator.Now i am not using is_superuser flag and instead i created a field in UserProfile model called is_admin_user and allowing the permission depend on the flag in UserProfile model.

If is_admin_user flag is set,he can access the application settings page,otherwise they can't access the settings page.While creating profile using is_admin_user flag,the default django is_superuser flag is set to false.Since i am using the decorator i am not able to access the settings page.If i click settings page it redirect to login page.

1.Is it possible to create any other custom thing for is_admin_user.

2.If i comment this line @user_passes_test(lambda u: u.is_superuser) ,able to move to settings page.

Need suggestion.

Use something like

@user_passes_test(lambda u: u.userprofile.is_admin_user)

You may need to change userprofile to your profile related_name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM