-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
34 lines (28 loc) · 1.14 KB
/
models.py
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
28
29
30
31
32
33
34
from sqlalchemy import * #specifically create_engine
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
#instantiate file
Base = declarative_base()
class Coach(Base):
__tablename__ = 'coach'
id = Column(Integer, primary_key = True)
name = Column(String)
years = Column(Integer)
salary = Column(Float)
sal_school = Column(String)
schools = relationship('School', secondary = 'joinedtable', back_populates = 'coaches')
class School(Base):
__tablename__ = 'school'
id = Column(Integer, primary_key = True)
name = Column(String)
years = Column(String)
winloss = Column(Float)
team_points = Column(Float)
opp_points= Column(Float)
coaches = relationship('Coach', secondary = 'joinedtable', back_populates = 'schools')
class JoinedTable(Base): #create this table for a many to many relationship
__tablename__ = 'joinedtable'
school_id = Column(Integer, ForeignKey('school.id'), primary_key =True)
coach_id = Column(Integer, ForeignKey('coach.id'), primary_key = True)
engine = create_engine('sqlite:///basketball.db')
Base.metadata.create_all(engine)