django template中如何判断用户所属group是否有指定的权限?
django中,我想判断一个group是否有指定的权限,但是遇到一点问题
view代码
from django.contrib.auth.models import User,Group,Permission
from django.db.models import Q
def users(request):
users = User.objects.filter(is_active=1).exclude(id=request.user.id)
groups = Group.objects.exclude(Q(name='customer') | Q(name='vendor') | Q(name='labour'))
permissions = Permission.objects.all()
return {
'all_users': users,
'all_groups' : groups,
'permissions' : permissions
}
template代码
<input type="checkbox" name="group_{{group.id}}_permission_{{permission.id}}" {%if 'condition' %} checked="checked" {% endif %} />
nibaby
10 years, 6 months ago