1

I am newbie to Django Rest Framework. I googled a lot and stuck on How to set User Role to User and strict to Permission.

My question is very basic but I don't know how to do it.

I want to create 2 types of Users:

1) Admin (Full Access)

2) Normal User (Limited Access)

I found some links but still on getting what to do: Django rest-framework per action permission django-rest-framework : setting per user permissions

Brown Bear
  • 19,655
  • 10
  • 58
  • 76
iNikkz
  • 3,729
  • 5
  • 29
  • 59

1 Answers1

2

you can separate users by is_staff property and use, standart rest permission isadminuser, for test you try this simple view

from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.views import APIView

class ExampleView(APIView):
    permission_classes = (IsAdminUser,)

    def get(self, request, format=None):
        content = {
            'status': 'request was permitted'
        }
        return Response(content)
Brown Bear
  • 19,655
  • 10
  • 58
  • 76
  • Thanks Brown. Actually, my requirement is more than just admin and user role. I can have 3 users. All have different roles and permission. Any help on it ? – iNikkz Aug 26 '17 at 17:17
  • 1
    you can use [custom-permissions](http://www.django-rest-framework.org/api-guide/permissions/#custom-permissions) for your own way – Brown Bear Aug 26 '17 at 17:20