from django.contrib.auth.models import Group def hasGroup(user,groupName): group = Group.objects.filter(name=groupName) return True if group in user.groups.all() else False
Сделайте так:
def hasGroup(user, groupName): return user.groups.filter(name=groupName).exists()
сохранит ваш запрос и будет работать так, как вы ожидали.