def filter_selected(queryset, name, value):
    """
    Filter a queryset with a lecture code.
    """
    query = [x.strip() for x in value.split(',')]
    base = queryset
    result = None

    for code in query:
        # Filter out lectures that has different code with our query.
        if result is None:
            result = base.filter(code=code)
        else:
            result = result.union(base.filter(code=code))

    return result