def main(): # add users beyonce = User(username="******", password="******") ariana = User(username="******", password="******") miley = User(username="******", password="******") session.add_all([beyonce, ariana, miley]) session.commit() # Make one user auction a baseball baseball = Item(name="baseball", description="Baseball from Babe Ruth's first home run", seller=ariana) session.add(baseball) session.commit() print("{} started an auction for {} at {}".format( baseball.seller, baseball.name, baseball.start_time.strftime('%m/%d/%y'))) # Have each other use two bids on the baseball starting_bid = Bid(price=100.00, item=baseball, bidder=ariana) bknowles_bid = Bid(price=150.00, item=baseball, bidder=beyonce) mcyrus_bid = Bid(price=200.00, item=baseball, bidder=miley) bid_list = [bknowles_bid, mcyrus_bid] session.add_all([starting_bid, bknowles_bid, mcyrus_bid]) session.commit() for bid in bid_list: print("{} placed a bid on a {} for {}".format(bid.bidder, bid.item, bid.price)) # Perform a query to find out which user placed the highest bid highest_bid = session.query(Bid).order_by(Bid.price.desc()).first() print("{} had the highest bid at ${}".format(highest_bid.bidder.username, highest_bid.price))
from tbay import User, Item,Bid, session ade=User(username = '******',password = '******') phil=User(username="******", password="******") jolade=User(username="******", password="******") Baseball= Item(name="Nike",description="sports shoes", seller=ade) bid1=Bid(price=3.00,bidder=phil, item_bid=Baseball) bid2=Bid(price=5.00, bidder=jolade, item_bid=Baseball) Baseball.price=[3.00,5.00] session.add_all([ade, Baseball,phil, jolade, bid1, bid2]) session.commit() print (max(Baseball.price))
from tbay import session, User, Item, Bid if __name__ == '__main__': andrew = User(username='******', password='******') scotty = User(username='******', password='******') parker = User(username='******', password='******') baseball = Item(name='baseball', description='Homerun ball hit by Michael Jordan during his brief stint in the minor leagues', user=andrew) bids1 = Bid(price=250, item=baseball) baseball.bids.append(bids1) scotty.bids.append(bids1) bidp1 = Bid(price=520, item=baseball) baseball.bids.append(bidp1) parker.bids.append(bidp1) bids2 = Bid(price=600, item=baseball) baseball.bids.append(bids2) scotty.bids.append(bids2) bidp2 = Bid(price=601, item=baseball) baseball.bids.append(bidp2) parker.bids.append(bidp2) session.add_all([andrew, scotty, parker, baseball, bids1, bids2, bidp1, bidp2]) session.commit()
user_id = Column(Integer, ForeignKey('users.id'), nullable=False) user = relationship('User', backref='bids') Base.metadata.create_all(engine) if __name__ == '__main__': from tbay import session from sqlalchemy import desc beyonce = User(username='******', password='******') christina = User(username='******', password='******') britney = User(username='******', password='******') microphone = Item(name="microphone", description="Mika's gold microphone.") bids = [ Bid(price=500.0, user=christina, item=microphone), Bid(price=1150.0, user=beyonce, item=microphone), Bid(price=200.0, user=christina, item=microphone), Bid(price=201.0, user=beyonce, item=microphone), ] session.add_all([beyonce, christina, britney, microphone] + bids) session.commit() highest_bid = (session.query(Bid).filter(Bid.item == microphone).order_by( desc(Bid.price)).first()) print(highest_bid.user.username) print(highest_bid.item.description)
from tbay import User, Item, Bid, session perry = User(name="Perry",password="******") baseball = Item(name="BaseBall") perry.items = [baseball] jesse = User(name="Jesse",password="******") monica = User(name="Monica",password="******") bid1 = Bid(price=23.8,bidder=jesse,item=baseball) bid2 = Bid(price=18.5, bidder=monica,item=baseball) session.add_all([perry, jesse, monica, baseball, bid1, bid2]) session.commit() highestBid = session.query(Bid).order_by(Bid.price.desc()).first() print(highestBid.price, highestBid.bidder.name)
from tbay import User, Item, Bid, session beyonce = User() beyonce.username = "******" beyonce.password = "******" sylvester = User() sylvester.username = "******" sylvester.password = "******" jayz = User() jane.username = "******" jane.password = "******" Base.metadata.create_all(engine) session.add_all([beyonce, sylvester, jayz]) session.commit() baseball = Item() headphones.name = "baseball" headphones.description = "Who wants to play ball? Get your baseball here!" session.add(baseball) session.commit()
from tbay import Item, User, Bid, session # Add three users to the database ryan = User(username='******', password='******') amy = User(username='******', password='******') audrey = User(username='******', password='******') paul = User(username='******', password='******') session.add_all([ryan, amy, audrey, paul]) session.commit() # Make one user auction a baseball baseball = Item( name='Autographed Baseball', description='A baseball signed by David Ortiz', start_time='2015-08-02 17:00:00.000000', owner=ryan ) football = Item( name='Autographed Football', description='A football signed by the Super Bowl Champion New England Patriots ', start_time='2015-08-02 17:00:00.000000', owner=audrey ) puck = Item( name='Autographed Hockey Puck', description='A hockey puck signed by Tuuka Rask', start_time='2015-08-02 17:00:00.000000', owner=ryan ) soccer = Item(
#Item2=Item(name="QuestBars",description="Protein Bars") #session.add(Vigs) #session.add(Teejay) #session.add(Item1) #session.add(Item2) #session.commit() #Userlist=session.query(User).filter(User.usrname=="Vigs").all() #for user in Userlist: # session.delete(user) #session.commit() #Userlist=session.query(User).filter(User.usrname=="TJ").all() #for user in Userlist: # session.delete(user) #session.commit() fender = Manufacturer(name="Fender") strat = Guitar(name="Stratocaster", manufacturer=fender) tele = Guitar(name="Telecaster") fender.guitars.append(tele) session.add_all([fender, strat, tele]) session.commit() for guitar in fender.guitars: print(guitar.name) print(tele.manufacturer.name)