How to give permissions to users in django.?

I am building a django ERP project, in which there will be multiple user's, admin,user, manager etc. Each of this user has separate user credentials to login. Each user have separate dashboard. I'm using local database for login function.

I want to give access to every user from admin dashboard, like view, edit,and delete, allow them to download csv file. I am trying to make privilege page for each user in admin dashboard. When a radio button or check box turn on, that respective user had to access the privilege.

You can use django's built-in permission system and also you can create your own custom permissions in django. If you need more clarity regarding this topics please add your sample code, i can help with that or otherwise you can refer the below link:

https://docs.djangoproject.com/en/5.0/topics/auth/default/#permissions-and-authorization

I have been using this in my project to manage different types of users

Creating a group

group_name = 'manager'
group_obj = Group.objects.filter(name=group_name)
if not group_obj:
    Group.objects.create(name=group_name)

Manage user access to the view

@api_view(['GET'])
def my_view(request):
    if request.user.is_authenticated and request.user.groups.filter(name__in=['manager']).exists():
        print('Access granted')
    else:
        print('Access denied')
Вернуться на верх