def pipe(*fns):
    """
    Given a list of queryset functions as *args, return a new queryset function
    that calls each function in turn, passing the return value of each as the
    argument to the next.
    """

    def piped(queryset):
        for fn in fns:
            queryset = fn(queryset)
        return queryset

    return piped