def main(): with dbapi.session: for x in dbapi.search(ProdItem): prod_id = get_real_prod_id(x.prod_id) itemgroup = dbapi.getone(ProdItemGroup, prod_id=prod_id) if itemgroup: dbapi.update(x, {'itemgroupid': itemgroup.uid}) else: print prod_id
def main(): with dbapi.session: to_be_deleted = [] for ig in dbapi.search(ProdItemGroup, **{'base_price_usd-gte': 31}): items = list(dbapi.search(ProdItem, itemgroupid=ig.uid)) prices = list(get_prices(dbapi, items)) if not prices: print 'delete item', ig.name if int(raw_input('delete?')): to_be_deleted.append(ig) continue price = min(prices) print ig.name, price print 'updated', dbapi.update(ig, {'base_price_usd': price}) print 'delete for sure', to_be_deleted if int(raw_input('delete')): map(dbapi.delete, to_be_deleted)