Reputation:
I want to implement view based permissions in same fashion as per object based permissions are applied. I know that when I have a model named A, three permissions can_add, can_edit, can_delete are created which is coupled with A. Now, can I have model that holds similar record but based on view. So, when I say can_view_login_page a permission record is created and when I place it above view as @method_decorator(permission_required('can_view_login_page'))
it allows or denies access based on role/group? My question might sound vague but I cant figure out how to put it.
Upvotes: 1
Views: 88
Reputation: 43300
It may not be exactly what you are looking for, but there is user_passes_test
You can use this method decorator to check whether a user has the correct credentials in order to see the page
from django.contrib.auth.decorators import user_passes_test
def can_view_login(user):
return user.can_view_login
@user_passes_test(can_view_login)
def my_view(request):
Upvotes: 1