Try something like this:

https://www.django-rest-framework.org/api-guide/permissions/ says: "To use
custom model permissions, override DjangoModelPermissions and set the
.perms_map property. Refer to the source code for details."(!)

from rest_framework.permissions import DjangoModelPermissions,
IsAuthenticated


class MyDjangoModelPermissions(DjangoModelPermissions):

    """

    Override `DjangoModelPermissions <
https://docs.djangoproject.com/en/dev/topics/auth/#permissions>`_

    to allow POST permission.

    """

    perms_map = {
            'GET': [],
            'OPTIONS': [],
            'HEAD': [],
            # 'POST': ['%(app_label)s.add_%(model_name)s'],
            'POST': [],
            'PUT': ['%(app_label)s.change_%(model_name)s'],
            'PATCH': ['%(app_label)s.change_%(model_name)s'],
            'DELETE': ['%(app_label)s.delete_%(model_name)s'],
        }

class MyViewSet(ModelViewSet):

    permission_classes = MyDjangoModelPermissions

On Tue, Sep 10, 2019 at 8:45 AM Jakob Damgaard Møller <jako...@gmail.com>
wrote:

> Or look into a custom permission:
> https://www.django-rest-framework.org/api-guide/permissions/#custom-permissions
>
> IsCreationOrAuthenticated like the: IsOwnerOrReadonly
> Instead of the request.method in permissions.SAFE_METHODS, see if the
> method == "POST"
>
> On Tue, Sep 10, 2019 at 2:30 PM siva gatti <siva.ga...@gmail.com> wrote:
>
>> class UserViewSet(viewsets.ModelViewSet):
>>     permission_classes =[IsAuthenticated]
>>     if(permission_classes):
>>         http_method_names = ['post']
>>         queryset = Documents.objects.all()
>>         serializer_class = DocumentSerializer
>> i am trying like this
>> my problem is unauth users can only access post method and auth users can
>> access post,get,put methods
>>
>> On Tue, Sep 10, 2019 at 5:47 PM siva gatti <siva.ga...@gmail.com> wrote:
>>
>>> unauthenticated users can only post but here they can do get ,delete and
>>> update
>>>
>>> On Tue, Sep 10, 2019 at 5:34 PM Harrys Asimakopoulos <xarhs...@gmail.com>
>>> wrote:
>>>
>>>> from rest_framework.permissions import AllowAny
>>>>
>>>> class UserViewSet(viewsets.ModelViewSet):
>>>>     permission_classes = [AllowAny,]
>>>>     queryset = Documents.objects.all()
>>>>     serializer_class = DocumentSerializer
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Django REST framework" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to django-rest-framework+unsubscr...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-rest-framework/f9f13934-f4b1-4bf7-a675-fc606cf21908%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/django-rest-framework/f9f13934-f4b1-4bf7-a675-fc606cf21908%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django REST framework" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-rest-framework+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-rest-framework/CAA9F9ijJTZgogDyg3ufKw%2Bm5sXuHpRFREfrdYyNKHmk%3D%3DnC_hg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-rest-framework/CAA9F9ijJTZgogDyg3ufKw%2Bm5sXuHpRFREfrdYyNKHmk%3D%3DnC_hg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> --
> Jakob Damgaard Olsen
> Tlf: 24613112
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-rest-framework+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-rest-framework/CAMmJSsHtbaiwAprJvD%2BOmNykXo6cE5o1%3DjCbx2Q1CRYF-0DKSA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-rest-framework/CAMmJSsHtbaiwAprJvD%2BOmNykXo6cE5o1%3DjCbx2Q1CRYF-0DKSA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Alan Crosswell
Associate VP & CTO

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/CAJaAdZiScCRmm4PQWJJTTu875PM1fbCFdNkQvNRBdZhYgNKOzg%40mail.gmail.com.

Reply via email to