Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot apply DjangoModelPermissions when rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly is enabled

I am trying to make MongoEngine work with Django REST framework. By following this link Getting mongoengine and django rest framework to play nice, I manage to get everything working, but have to disable "PERMISSION CLASSES" in REST framework, like below

'DEFAULT_PERMISSION_CLASSES': [ #'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly' ]

Otherwise, I get this error "Cannot apply DjangoModelPermissions on a view that does not have .model or .queryset property.". The reason seems to be that the returned value from "Collection.objects" or "Collection.objects.all()" can not pass "has_permission" function in permission.py in REST framework.

Could anyone help to look at this?

like image 455
Le Wang Avatar asked Dec 20 '22 13:12

Le Wang


1 Answers

Or you can just add:

from rest_framework import permissions

and in the view classes add

permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
like image 170
Abdelhak Avatar answered Dec 22 '22 10:12

Abdelhak