Reputation: 43
Can someone explain with an example or a tutorial of how can i allow model's view using the permissions that this user has. for example i have 2 users and 6 tables (models), I set that each one have permission for 3 tables, when the user access through the api authentication just allow access to the tables that he has permissions.
PD: sorry i don't speak english.
Upvotes: 0
Views: 171
Reputation: 5819
Since it appears that you're using django-rest-framework, I recommend you look at the documentation on permissions for django-rest-framework. Specifically, the section you will want is DjangoModelPermissions.
An example of how you would implement this (assuming a class based view) would look like:
from rest_framework.permissions import DjangoModelPermissions
from rest_framework.views import APIView
from .models import MyModel
class MyView(APIView):
permission_classes = (DjangoModelPermissions,)
queryset = MyModel.objects.all()
Keep in mind that, as stated in the documentation, you must provide a queryset
attribute on the view class in order for this to work.
Upvotes: 1