现在如何在 Django 中处理每个对象的权限?

How to handle per object permission in Django nowadays?

我正要使用 django-guardian,直到我在官方文档中遇到以下内容:

https://docs.djangoproject.com/en/stable/topics/auth/customizing/#handling-authorization-in-custom-backends

Permissions can be set not only per type of object, but also per specific object instance. By using the has_add_permission(), has_change_permission() and has_delete_permission() methods provided by the ModelAdmin class, it is possible to customize permissions for different object instances of the same type.

这是否意味着更新版本的 Django 不再需要 django-guardian?

请说明。

确实,在阅读文档时,我很兴奋 Django 会开箱即用地满足“每个对象权限检查”的需求,especially in the admin,理解我如何做只是时间问题可以激活它。

然而,this does not seem to always be the case.

Django undoubtedly strives 为这样的实现提供了依据 (API),但这种实现有时需要良好的编码技巧和对 Django 的理解。

开发人员会通过 creating the app 将这些工具组合在一起以满足其需要。这可能很容易,也可能...不太容易!

这种相互矛盾的信息构成了我的网络抓取的基础,它专注于找到解决“per-object 权限”问题的方法,不知何故......有效地满足我的项目需求或规模,当然还有我自己的编码到目前为止的技能和Django理解。

Django-guardian seems to be the most robust, full-fledged, full-blown application for this purpose, and it also has a 3 years old open issue 关于其管理集成。

还有其他 more lightweight django applications 可以满足特定需求 production-stable。

虽然在这个有点棘手的任务中试图维持生计,但我倾向于使用 django-rules,因为它简单且专注于我的功能需求。