1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2024-12-24 17:42:23 +00:00

Add view permission in REST API

This commit is contained in:
Alexandre Iooss 2019-08-17 12:48:53 +02:00
parent 6a79169496
commit d6df704d09
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
2 changed files with 17 additions and 1 deletions

16
med/permissions.py Normal file
View File

@ -0,0 +1,16 @@
from rest_framework.permissions import DjangoModelPermissions
class DjangoViewModelPermissions(DjangoModelPermissions):
"""
Add view permission
"""
perms_map = {
'GET': ['%(app_label)s.view_%(model_name)s'],
'OPTIONS': ['%(app_label)s.view_%(model_name)s'],
'HEAD': ['%(app_label)s.view_%(model_name)s'],
'POST': ['%(app_label)s.add_%(model_name)s'],
'PUT': ['%(app_label)s.change_%(model_name)s'],
'PATCH': ['%(app_label)s.change_%(model_name)s'],
'DELETE': ['%(app_label)s.delete_%(model_name)s'],
}

View File

@ -154,7 +154,7 @@ STATIC_URL = '/static/'
# Django REST Framework
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissions',
'med.permissions.DjangoViewModelPermissions',
]
}