如何为Django管理站点创建自定义权限
默认情况下,当我创建模型Django时,就会给出权限,例如
add/change/delete/view
我将上述任何权限授予特定用户,则该用户可以从该模型中查看所有对象。但是我想向他们展示与外国钥匙相关的对象。
假设
我有一个书籍模型
class Book(models.Model):
title = models.CharField(max_length=100)
author = models.ForeignKey(
User, on_delete=models.CASCADE
)
,如果我想授予作者许可,他们只能从Django管理员中查看他们的链接书籍。
我该怎么做?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一切都发生在Django Meta类中。只需按照 django documantation> django documantation
您要操纵默认许可,请按照这些将此添加到您的模型中。
Everything happens in the Django Meta class. Just follow what the Django Documantation says:
If you want to manipulate the default permission, you follow these documentation explanation an add this to you model.