2👍
✅
I’d use user_passes_test:
from django.contrib.auth.decorators import user_passes_test
def manage_access(user):
permissions_list = ['app.perm1', 'app.perm2', 'app.perm3', ]
for permission in permissions_list:
if user.has_perm(permission):
return True
return False
@user_passes_test(manage_access)
def my_view(request):
#view code
If you need anything more complex (e.g: permission list varies based on the view), I’d consider writing a custom decorator.
Source:stackexchange.com