@register.assignment_tag
def filter_queryset_by(queryset, **filters):
    if not getattr(queryset, 'query', False):
        return queryset

    cachekey = u'filterquerysetby-{0}'.format(hash(unicode(queryset.query)))
    _cache = cache.get(cachekey)
    if _cache:
        return _cache

    # check for __in lookups and split the param
    found_in_lookup = None
    for key in filters.keys():
        if '__in' in key:
            found_in_lookup = key

    if found_in_lookup:
        filters[found_in_lookup] = filters[found_in_lookup].split(',')

    if not queryset.query.can_filter():
        # create new queryset based on the ids and apply filter
        ids = [i.id for i in queryset]
        queryset = queryset.model.objects.filter(id__in=ids).filter(**filters)
        return queryset

    containers = queryset.filter(**filters)
    cache.set(cachekey, containers, settings.OPPS_CACHE_EXPIRE)
    return containers
Filter object list
dataset/ETHPy150Open opps/opps/opps/containers/templatetags/container_tags.py/filter_queryset_by