我可以将Django的内置身份验证组用作朋友列表吗?我想为每个用户创建每个组,我看到的主要优点是可以使用权限。
如果选择使用友谊模型而不是组,是否可以向友谊模型添加权限?
谢谢
如果您在这里阅读:
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')),
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句