from django import template
from django.forms import CheckboxInput


register = template.Library()


@register.filter(name='addclass')
def addclass(value, arg):
    return value.as_widget(attrs={'class': arg})


@register.filter(name='is_checkbox')
def is_checkbox(field):
    return field.field.widget.__class__.__name__ == \
        CheckboxInput().__class__.__name__

from django import template
from django.forms import CheckboxInput
from django.contrib.auth.models import Group


register = template.Library()


@register.filter(name='addclass')
def addclass(value, arg):
    return value.as_widget(attrs={'class': arg})


@register.filter(name='is_checkbox')
def is_checkbox(field):
    return field.field.widget.__class__.__name__ == \
        CheckboxInput().__class__.__name__


@register.filter(name='in_group')
def in_group(user, group_name):
    group = Group.objects.get(name=group_name)
    return True if group in user.groups.all() else False

Add templatetag to check if user included in group
Add templatetag to check if user included in group

  from django import template
  from django.forms import CheckboxInput
+ from django.contrib.auth.models import Group
  
  
  register = template.Library()
  
  
  @register.filter(name='addclass')
  def addclass(value, arg):
      return value.as_widget(attrs={'class': arg})
  
  
  @register.filter(name='is_checkbox')
  def is_checkbox(field):
      return field.field.widget.__class__.__name__ == \
          CheckboxInput().__class__.__name__
  
+ 
+ @register.filter(name='in_group')
+ def in_group(user, group_name):
+     group = Group.objects.get(name=group_name)
+     return True if group in user.groups.all() else False
+ 
Add templatetag to check if user included in group
## Code Before:
from django import template
from django.forms import CheckboxInput


register = template.Library()


@register.filter(name='addclass')
def addclass(value, arg):
    return value.as_widget(attrs={'class': arg})


@register.filter(name='is_checkbox')
def is_checkbox(field):
    return field.field.widget.__class__.__name__ == \
        CheckboxInput().__class__.__name__

## Instruction:
Add templatetag to check if user included in group
## Code After:
from django import template
from django.forms import CheckboxInput
from django.contrib.auth.models import Group


register = template.Library()


@register.filter(name='addclass')
def addclass(value, arg):
    return value.as_widget(attrs={'class': arg})


@register.filter(name='is_checkbox')
def is_checkbox(field):
    return field.field.widget.__class__.__name__ == \
        CheckboxInput().__class__.__name__


@register.filter(name='in_group')
def in_group(user, group_name):
    group = Group.objects.get(name=group_name)
    return True if group in user.groups.all() else False
