gpt4 book ai didi

Django 2.1 查看权限

转载 作者:行者123 更新时间:2023-12-03 23:15:37 25 4
gpt4 key购买 nike

Django Doc声明新的查看权限已添加到 Django 2.1,但没有进一步说明如何使用它,尤其是在 Django 管理站点上。

我的理解是这将是一种只读权限,但我将感谢任何对这一新权限及其在管理站点上的行为有更好理解的人的更多说明

最佳答案

您是 正确 . Django 2.1 release notes描述这个变化:

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.



此外还有 ModelAdmin.has_view_permission [Django-doc] 的文档权限解释如下:

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.



因此,在这种情况下,“更改”权限意味着“查看”权限(这是相当合乎逻辑的,因为更改对象而无法首先看到它会很奇怪)。

关于Django 2.1 查看权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51515577/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com