I have a template filter in Django that looks ugly and not very pythonic. Is there a way to combine all the get requests into a list?
@register.filter(name='is_supervisor')
def is_in_group(user):
group = Group.objects.get(name="security supervisor")
group1 = Group.objects.get(name="cage supervisor")
group2 = Group.objects.get(name="casino supervisor")
group3 = Group.objects.get(name="food bev supervisor")
return True if group or group1 or group2 or group3 in user.groups.all() else False
I tried using a Q filter for chaining them together but that did not work. I have also tried:
@register.filter(name='is_supervisor')
def is_in_group(user):
types = ["security supervisor", "cage supervisor",
"casino supervisor", "food bev supervisor"]
for name in types:
test1 = Group.objects.get(name=name)
return True if test1 in user.groups.all() else False