forked from learn-co-curriculum/python-p3-freebie-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.py
More file actions
28 lines (22 loc) · 868 Bytes
/
debug.py
File metadata and controls
28 lines (22 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from models import Base, Dev, Company, Freebie
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
# Connect to an in-memory SQLite database (you can change this to your db)
engine = create_engine('sqlite:///:memory:', echo=True)
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()
# Create sample data
company = Company(name='Cool Company', founding_year=2000)
dev = Dev(name='Alice')
session.add(company)
session.add(dev)
session.commit()
# Create a freebie
freebie = Freebie(item_name='Sticker', value=10, dev=dev, company=company)
session.add(freebie)
session.commit()
# Print to verify relationships
print(freebie.dev.name) # Should print 'Alice'
print(freebie.company.name) # Should print 'Cool Company'
print(dev.freebies) # Should show the freebie(s) collected by dev