Django 1.5,Python 2.6
该模型会在某些条件下自动创建用户:
User.objects.get_or_create(username=new_user_name, is_staff=True) u = User.objects.get(username=new_user_name) u.set_password('temporary')
除了设置用户名,密码和is_staff状态外,我还要设置用户的权限-类似:
u.user_permissions('Can view poll')
要么
u.set_permissions('Can change poll')
这可能吗?谢谢!
用途add和remove方法:
add
remove
from django.contrib.auth.models import Permission permission = Permission.objects.get(name='Can view poll') u.user_permissions.add(permission)