Search code examples
djangopython-3.xdjango-permissions

Django 2.1 View Permission


The Django Doc states that the new View Permission is added to Django 2.1 but without further clarifications on how this will be used especially on the Django Admin Site.

It is my understanding this will be kind of ReadOnly Permission, but I will appreciate more clarifications from any one with better understanding on this new permission and its behavior on the Admin Site


Solution

  • You are correct. The Django 2.1 release notes describe this change:

    Model "view" permission

    A "view" permission is added to the model Meta.default_permissions. The new permissions will be created automatically when running migrate.

    This allows giving users read-only access to models in the admin. ModelAdmin.has_view_permission() is new. The implementation is backwards compatible in that there isn’t a need to assign the "view" permission to allow users who have the "change" permission to edit objects.

    Furthermore the documentation for ModelAdmin.has_view_permission [Django-doc] permission explains it like:

    ModelAdmin.has_view_permission(request, obj=None)

    Should return True if viewing obj is permitted, False otherwise. If obj is None, should return True or False to indicate whether viewing of objects of this type is permitted in general (e.g., False will be interpreted as meaning that the current user is not permitted to view any object of this type).

    The default implementation returns True if the user has either the "change" or "view" permission.

    So in this case, the "change" permission implies the "view" permission (which is rather logical, since it would be strange to change an object, without being able to see it first).