我可以使用Django的auth组作为朋友列表吗?对于每个用户,我希望创建每个组,我看到的主要优势是使用权限的可能性。
如果选择使用友谊模型而不是组,是否可以向友谊模型添加权限?
谢谢
发布于 2017-02-18 21:51:47
如果你读了这里
Beyond permissions, groups are a convenient way to categorize users to
apply some label, or extended functionality, to them. For example, you
could create a group 'Special users', and you could write code that would
do special things to those users -- such as giving them access to a
members-only portion of your site, or sending them members-only email
messages.
...对我来说,一般情况下,你可以对他们使用不同的标签,比如“亚历克斯朋友”或“马蒂朋友”,但你真的想这么做吗?更简单的方法是创建新的模型,并将Django组留给他们应该做的事情。
如果创建模型,可以对实例应用权限或在模型的Meta部分中创建自己的权限,如下所示:
class Meta:
permissions = (
('participate_contest', _('Participate Contest')),
('unparticipate_contest', _('Unparticipate Contest')),
)https://stackoverflow.com/questions/42320948
复制相似问题