diff options
author | emkael <emkael@tlen.pl> | 2017-01-06 00:28:40 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2017-01-06 00:28:40 +0100 |
commit | 3698d02c9a57e13070bae5d4b51e40d9879522bb (patch) | |
tree | dc8a4f22d9cd37ef7d982090cc9e1823a7ef8d44 | |
parent | 3827de159894a294af1eef25ae365f8c716e1c1b (diff) |
Player and team information added to model
-rw-r--r-- | ausbutler/model.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/ausbutler/model.py b/ausbutler/model.py index d3e4c27..79784bf 100644 --- a/ausbutler/model.py +++ b/ausbutler/model.py @@ -1,6 +1,7 @@ from cached_property import cached_property -from sqlalchemy import Column, MetaData, Table, func, join, literal +from sqlalchemy import Column, MetaData, Table, ForeignKey, func, join, literal from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import relationship from sqlalchemy.types import Float, Integer, String from .db import get_session @@ -8,9 +9,26 @@ from .db import get_session Base = declarative_base() session = get_session() +class Team(Base): + __table__ = Table('teams', MetaData(bind=session.bind), + autoload=True) + + def __repr__(self): + return self.shortname.encode('utf8') + +class Player(Base): + __table__ = Table('players', MetaData(bind=session.bind), + Column('id', Integer, primary_key=True), + Column('team', Integer, ForeignKey(Team.id)), + autoload=True) + team_ = relationship(Team, uselist=False) + + def __repr__(self): + return ('%s %s' % (self.gname, self.sname)).encode('utf8') + class AusButler(Base): __tablename__ = 'aus_butler' - id = Column(Integer, primary_key=True) + id = Column(Integer, ForeignKey(Player.id), primary_key=True) match = Column(Integer, primary_key=True) segment = Column(Integer, primary_key=True) score = Column(Float) @@ -18,6 +36,7 @@ class AusButler(Base): opp_score = Column(Float) corrected_score = Column(Float) board_count = Column(Integer) + player = relationship('Player', uselist=False) @cached_property def table(self): |