'Bulk assigns permissions with given ``perm`` for an objects in ``queryset`` and
``user_or_group``.'

def bulk_assign_perm(self, perm, user_or_group, queryset):

    ctype = get_content_type(queryset.model)
    if (not isinstance(perm, Permission)):
        permission = Permission.objects.get(content_type=ctype, codename=perm)
    else:
        permission = perm
    checker = ObjectPermissionChecker(user_or_group)
    checker.prefetch_perms(queryset)
    assigned_perms = []
    for instance in queryset:
        if (not checker.has_perm(permission.codename, instance)):
            kwargs = {u'permission': permission, self.user_or_group_field: user_or_group}
            if self.is_generic():
                kwargs[u'content_type'] = ctype
                kwargs[u'object_pk'] = instance.pk
            else:
                kwargs[u'content_object'] = instance
            assigned_perms.append(self.model(**kwargs))
    self.model.objects.bulk_create(assigned_perms)
    return assigned_perms
