diff options
author | emkael <emkael@tlen.pl> | 2014-10-29 11:11:54 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2014-10-29 11:11:54 +0100 |
commit | a5abdf6f6ad1c51a0aaea253560e742f690cb16d (patch) | |
tree | 6a96f0cb0d57632b6d7b19e1700b3fdaa780e9d6 /f1elo/model.py | |
parent | e8ef92b0254909df8291d144d72bcb837817cf51 (diff) |
* moving find_driver to static Driver method
Diffstat (limited to 'f1elo/model.py')
-rw-r--r-- | f1elo/model.py | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/f1elo/model.py b/f1elo/model.py index 7865198..96a9ef4 100644 --- a/f1elo/model.py +++ b/f1elo/model.py @@ -25,6 +25,16 @@ class Driver(Base): return ranks[-1] return None + @staticmethod + def fetch(name, country, session): + driver = session.query(Driver).filter(Driver.driver==name).first() + if not driver: + driver = Driver() + driver.driver = name + driver.country = country + session.add(driver) + return driver + driver_entry = Table('driver_entries', Base.metadata, Column('_driver', Integer, ForeignKey('drivers.id')), Column('_entry', Integer, ForeignKey('entries.id')), @@ -85,16 +95,5 @@ class Ranking(Base): def __repr__(self): return ("%s: %0.2f (%s)" % (self.driver.__repr__().decode('utf8'), self.ranking, self. rank_date)).encode('utf8') -def find_driver(name, country, session): - driver = session.query(Driver).filter(Driver.driver==name).first() - if driver: - return driver - else: - driver = Driver() - driver.driver = name - driver.country = country - session.add(driver) - return driver - __all__ = ['Driver', 'Entry', 'Ranking', 'Race', 'RaceType'] |