def create_relation_input(node, modelclass, metadata, row):
    vlist = []
    current = getattr(row, metadata.colname)
    if metadata.collection == "MappedCollection":
        current = current.values()
    relmodel = getattr(modelclass, metadata.colname).property.mapper.class_
    q = dbsession.query(relmodel)
    try:
        order_by = relmodel.ROW_DISPLAY[0]
        q = q.order_by(getattr(relmodel, order_by))
    except (__HOLE__, IndexError):
        pass
    for relrow in q:
        if metadata.uselist:
            if relrow in current:
                vlist.append((relrow.id, str(relrow), True))
            else:
                vlist.append((relrow.id, str(relrow), False))
        else:
            if relrow is current:
                vlist.append((relrow.id, str(relrow), True))
            else:
                vlist.append((relrow.id, str(relrow), False))
    if metadata.nullable:
        vlist.insert(0, (0, "----"))
    elid = "id_" + metadata.colname
    node.add_label(metadata.colname, elid)
    return node.add_select(vlist, name=metadata.colname, multiple=metadata.uselist, id=elid)
dataset/ETHPy150Open kdart/pycopia/storage/pycopia/db/webhelpers.py/create_relation_input