python - Object permissions with read only access for anonymous users in Django Rest Framework -
the problem
i using django rest framework - , far have been using djangoobjectpermissions
permissions class. use django-rules
determine users have permissions objects.
however, permissions class seems deny read access anonymous users.
i need find best way allow read-only access users (authenticated or not). additions, modifications , deletions - object permissions should applied normal.
what best approach solving problem? django not seem provide can_view
permission default.
perhaps involve manually adding can_view
permission each model. or maybe it's better somehow implement djangoobjectpermissionsoranonreadonly
permissions class?
the fix simple. it's possible create custom permissions class extending djangoobjectpermissions
, , override authenticated_users_only
variable.
class djangoobjectpermissionsoranonreadonly(djangoobjectpermissions): authenticated_users_only = false
Comments
Post a Comment