def sort_siblings(siblings, key, reverse=False):
    """ Sorts the siblings by the given key, writing the order to the
    database.

    """
    new_order = sorted(siblings, key=key, reverse=reverse)
    for ix, sibling in enumerate(new_order):
        sibling.order = ix
