from models import db, Puppy, Toy, Owner rufus = Puppy('Rufus') fido = Puppy('Fido') db.session.add_all([rufus, fido]) db.session.commit() print(Puppy.query.all()) rufus = Puppy.query.filter_by(name='Rufus').first() print(rufus) jose = Owner('Jose', rufus.id) toy1 = Toy('Chew toy', rufus.id) toy2 = Toy('Ball', rufus.id) db.session.add_all([jose, toy1, toy2]) db.session.commit() rufus = Puppy.query.filter_by(name='Rufus').first() print(rufus) rufus.report_toys()
from models import db, Puppy, Owner, Toy brigite = Puppy('Brigite') olie = Puppy('Ollie') # ADD db.session.add_all([brigite, olie]) db.session.commit() print(Puppy.query.all()) brigite = Puppy.query.filter_by(name='Brigite').first() mima = Owner('Mima', brigite.id) # Give brigite some toys biter = Toy('Biter', brigite.id) ball = Toy('Ball', brigite.id) db.session.add_all([mima, biter, ball]) db.session.commit() brigite = Puppy.query.filter_by(name='Brigite').first() print(brigite) print(brigite.report_toys())
# check print(Puppy.query.all()) lluvia = Puppy.query.filter_by(name='Lluvia').first() travieso = Puppy.query.filter_by(name='Travieso').first() #Create owner object alex = Owner('Alex', lluvia.id) ale = Owner('Ale', travieso.id) # give lluvia some toys toy1 = Toy('Chew Toy', lluvia.id) toy2 = Toy('Ball', lluvia.id) # give travieso some toys toy3 = Toy('Chew Toy', travieso.id) toy4 = Toy('Ball', travieso.id) db.session.add_all([alex, ale, toy1, toy2, toy3, toy4]) db.session.commit() # grab lluvia and travieso lluvia = Puppy.query.filter_by(name='Lluvia').first() travieso = Puppy.query.filter_by(name='Travieso').first() print(lluvia) print(lluvia.report_toys()) print(travieso) print(travieso.report_toys())
# Creating 2 puppies rufus = Puppy('Rufus') fido = Puppy('Fido') # ADD Puppies to db db.session.add_all([rufus,fido]) db.session.commit() # Check! print(Puppy.query.all()) rufus = Puppy.query.filter_by(name='Rufus').all()[0] print(rufus) # Create owner object jose = Owner('Jose',rufus.id) # Give Rufus some toys toy1 = Toy('Chew Toy', rufus.id) toy2 = Toy('Ball', rufus.id) db.session.add_all([jose,toy1,toy2]) db.session.commit() # GRAB RUFUS AFTER THOSE ADDITIONS! rufus = Puppy.query.filter_by(name='Rufus').first() print(rufus) print(rufus.report_toys())
# create entries into the tables from models import db, Puppy, Owner, Toy tarzan = Puppy('Tarzan') bobik = Puppy('Bobik') db.session.add_all([tarzan, bobik]) db.session.commit() print(Puppy.query.all()) tarzan = Puppy.query.filter_by(name='Tarzan').first() print(tarzan) peter = Owner('Peter', tarzan.id) toy1 = Toy("chew toy", tarzan.id) toy2 = Toy('Ball', tarzan.id) db.session.add_all([peter, toy1, toy2]) db.session.commit() tarzan = Puppy.query.filter_by(name='Tarzan').first() print(tarzan) print(tarzan.report_toys())