且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

控制Django身份验证用户对特定对象实例的访问

更新时间:2023-12-02 10:03:46

这被称为行级权限,这是一个非常普遍的问题。请参阅此处以获取所有解决问题的应用。

This is called row-level permissions and it's a very common problem. See here for all the apps that solve it.

如果您只需要执行该特定测试,就选择像您这样的自定义解决方案(尽管由于它是样板,所以***将其移至装饰器中)。否则,只需使用现有应用。

If that particular test is all you need to do, go for a custom solution like yours (though, since it's boilerplate, it's preferable to move it to a decorator). Otherwise, just use an existing app.