django-permissions

Django Python : adding custom permissions to specific users

百般思念 提交于 2021-02-07 09:57:40
问题 Models.py class Meta: permissions = ( ("can_add_data","can add a new data"), ) This is the custom permission I've created in Models.py and I've also created these users. Users in Django Admin ie., http://localhost:8000/admin How do I give permission to specific users so that I can use @permission_required('myapp.can_add_data') in views.py and also where do I write the snippet? (in which file) I'm a beginner at this so if there are any mistakes please let me know. 回答1: You can assign

Django Python : adding custom permissions to specific users

旧时模样 提交于 2021-02-07 09:57:26
问题 Models.py class Meta: permissions = ( ("can_add_data","can add a new data"), ) This is the custom permission I've created in Models.py and I've also created these users. Users in Django Admin ie., http://localhost:8000/admin How do I give permission to specific users so that I can use @permission_required('myapp.can_add_data') in views.py and also where do I write the snippet? (in which file) I'm a beginner at this so if there are any mistakes please let me know. 回答1: You can assign

DRF Viewset remove permission for detail route

荒凉一梦 提交于 2020-12-30 08:30:03
问题 I have a basic Viewset: class UsersViewSet(viewsets.ModelViewSet): permission_classes = (OnlyStaff,) queryset = User.objects.all() serializer_class = UserSerializer It is bind to the /api/users/ endpoint. I want to create a user profile page, so I need only a particular user, so I can retrieve it from /api/users/<id>/ , but the problem is that I want /api/users/<id>/ to be allowed to anyone, but /api/users/ to keep its permission OnlyStaff , so no one can have access to the full list of users

DRF Viewset remove permission for detail route

瘦欲@ 提交于 2020-12-30 08:28:23
问题 I have a basic Viewset: class UsersViewSet(viewsets.ModelViewSet): permission_classes = (OnlyStaff,) queryset = User.objects.all() serializer_class = UserSerializer It is bind to the /api/users/ endpoint. I want to create a user profile page, so I need only a particular user, so I can retrieve it from /api/users/<id>/ , but the problem is that I want /api/users/<id>/ to be allowed to anyone, but /api/users/ to keep its permission OnlyStaff , so no one can have access to the full list of users