def METHOD_NAME(name, code_names):
    group = Group.objects.filter(name__iexact=name).first()
    if group is None:
        group = Group.objects.create(name=name)
        for permission_codename in code_names:
            permissions = Permission.objects.filter(
                codename=permission_codename, content_type__app_label='manager'
            )
            for permission in permissions.iterator():
                group.permissions.add(permission)
        group.save()
    return group