X-Git-Url: http://git.veekun.com/zzz-pokedex.git/blobdiff_plain/ac23f56d99b199b1c3f149159e1d2a1b5028cbc9..94718259a763ab76944abf5aa26ab77b6da6c9e8:/pokedex/db/tables.py diff --git a/pokedex/db/tables.py b/pokedex/db/tables.py index 508556f..c2cf297 100644 --- a/pokedex/db/tables.py +++ b/pokedex/db/tables.py @@ -185,7 +185,8 @@ class LocationArea(TableBase): class LocationAreaEncounterRate(TableBase): __tablename__ = 'location_area_encounter_rates' location_area_id = Column(Integer, ForeignKey('location_areas.id'), primary_key=True, nullable=False, autoincrement=False) - encounter_type_id = Column(Integer, ForeignKey('encounter_terrain.id'), primary_key=True, nullable=False, autoincrement=False) + encounter_terrain_id = Column(Integer, ForeignKey('encounter_terrain.id'), primary_key=True, nullable=False, autoincrement=False) + version_id = Column(Integer, ForeignKey('versions.id'), primary_key=True, autoincrement=False) rate = Column(Integer, nullable=True) class Machine(TableBase): @@ -268,6 +269,7 @@ class Move(TableBase): class Nature(TableBase): __tablename__ = 'natures' + __singlename__ = 'nature' id = Column(Integer, primary_key=True, nullable=False) name = Column(Unicode(8), nullable=False) decreased_stat_id = Column(Integer, ForeignKey('stats.id'), nullable=False) @@ -350,6 +352,22 @@ class Pokemon(TableBase): return self + ### Not forms! + + def stat(self, stat_name): + """Returns a PokemonStat record for the given stat name (or Stat row + object). Uses the normal has-many machinery, so all the stats are + effectively cached. + """ + if isinstance(stat_name, Stat): + stat_name = stat_name.name + + for pokemon_stat in self.stats: + if pokemon_stat.stat.name == stat_name: + return pokemon_stat + + return None + class PokemonAbility(TableBase): __tablename__ = 'pokemon_abilities' pokemon_id = Column(Integer, ForeignKey('pokemon.id'), primary_key=True, nullable=False, autoincrement=False)