(items, obj, attr, model, db)
Takes a list of items, and object, the attribute of that object that needs to be replaced, the model corresponding the items, and the db

    Sets the objects attribute to the list of items received. DOES NOT SAVE TO DB.
Takes a list of items, and object, the attribute of that object that needs to be replaced, the model corresponding the items, and the db
Takes a list of items and object the attribute of that object that needs to be replaced the model corresponding the items and the db
def replace_list(items, obj, attr, model, db):
    """Takes a list of items, and object, the attribute of that object that needs to be replaced, the model corresponding the items, and the db

    Sets the objects attribute to the list of items received. DOES NOT SAVE TO DB.
    """
    new_list = []
    if not hasattr(obj, attr):
        raise LookupError('The object does not have the {} attribute'.format(attr))

    for item in items:
        new_item, _ = get_or_create(db.session, model, **item)
        new_list.append(new_item)
    setattr(obj, attr, new_list)
def replace_list ( items , obj , attr , model , db ) : new_list = [ ] if not hasattr ( obj , attr ) : raise LookupError ( 'The object does not have the {} attribute' . format ( attr ) ) for item in items : new_item , _ = get_or_create ( db . session , model , * * item ) new_list . append ( new_item ) setattr ( obj , attr , new_list )