djangoguardian权限控制测试-创新互联
导入model
In [1]: from guardian.shortcuts import *
In [2]: from resources.models import *
In [3]: from django.contrib.auth.models import *
获取id为2 的 user
In [4]: user = User.objects.get(id=2)
In [24]: host = Host.objects.get(id=1)
In [25]: script = Script.objects.get(id=2)
注销权限:
In [28]: remove_perm('operate_host',user,host)
In [30]: user = User.objects.get(id =2)
Out[31]:
测试user是对于host实例否有 operate_host
In [32]: user.has_perm('operate_host',host)
Out[32]: False
注册user用户 对于host实例的operate权限
In [33]: assign('operate_host',user,host)
Out[33]:
测试user是对于host实例否有 operate_host
In [34]: user.has_perm('operate_host',host)
Out[34]: True
In [36]: assign('use_scripts',user,script)
Out[36]:
网站栏目:djangoguardian权限控制测试-创新互联
分享URL:http://ybzwz.com/article/cedipi.html
In [1]: from guardian.shortcuts import *
In [2]: from resources.models import *
In [3]: from django.contrib.auth.models import *
获取id为2 的 user
In [4]: user = User.objects.get(id=2)
In [24]: host = Host.objects.get(id=1)
In [25]: script = Script.objects.get(id=2)
注销权限:
In [28]: remove_perm('operate_host',user,host)
In [30]: user = User.objects.get(id =2)
Out[31]:
测试user是对于host实例否有 operate_host
In [32]: user.has_perm('operate_host',host)
Out[32]: False
注册user用户 对于host实例的operate权限
In [33]: assign('operate_host',user,host)
Out[33]:
测试user是对于host实例否有 operate_host
In [34]: user.has_perm('operate_host',host)
Out[34]: True
In [36]: assign('use_scripts',user,script)
Out[36]:
网站栏目:djangoguardian权限控制测试-创新互联
分享URL:http://ybzwz.com/article/cedipi.html