@register.filter_function
def random_slice(value, arg=1):
    """
    Returns one or more random item(s) from the list or if it's a queryset a new filtered queryset.
    """
    try:
        arg = int(arg)
    except ValueError:
        raise Exception(arg % 'Invalid argument: %s')

    if type(value) == QuerySet:
        pks = list(value.values_list('pk', flat=True))
        random_pks = random_slice_list(pks, arg)
        return value.filter(pk__in=random_pks)
    elif type(value) == list:
        return random_slice_list(value, arg)
    else:
        return value[:arg]
dataset/ETHPy150Open baskoopmans/djcommon/djcommon/templatetags/common.py/random_slice/swapped operands of `%`