Adicionar 2 rotas
This commit is contained in:
0
api/models/__init__.py
Normal file
0
api/models/__init__.py
Normal file
24
api/models/pokemon_owned.py
Normal file
24
api/models/pokemon_owned.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from api.app import db, ma
|
||||
from .trainer import *
|
||||
|
||||
class PokemonOwned(db.Model):
|
||||
__tablename__ = "pokemons_owned"
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
name = db.Column(db.Text(50), unique=True, index=True, nullable=False)
|
||||
level = db.Column(db.Integer)
|
||||
pokemon_id = db.Column(db.Integer)
|
||||
trainer_id = db.Column(db.Integer, db.ForeignKey("trainers.id"), index=True)
|
||||
|
||||
def __init__(self, name, level, pokemon_id, trainer_id):
|
||||
self.name = name
|
||||
self.level = level
|
||||
self.pokemon_id = pokemon_id
|
||||
self.trainer_id = trainer_id
|
||||
|
||||
class PokemonOwnedSchema(ma.Schema):
|
||||
class Meta:
|
||||
fields = ('id', 'name', 'level', 'pokemon_data')
|
||||
|
||||
pokemon_owned_schema = PokemonOwnedSchema()
|
||||
pokemon_owned_schemas = PokemonOwnedSchema(many=True)
|
@@ -14,7 +14,7 @@ class InvalidTeam(Exception):
|
||||
class Trainer(db.Model):
|
||||
__tablename__ = "trainers"
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True, unique=True, autoincrement=True)
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
nickname = db.Column(db.String(20), unique=True, nullable=False, index=True)
|
||||
first_name = db.Column(db.String(30), nullable=False)
|
||||
last_name = db.Column(db.String(30), nullable=False)
|
||||
@@ -22,6 +22,7 @@ class Trainer(db.Model):
|
||||
password = db.Column(db.String(200), nullable=False)
|
||||
team = db.Column(db.String(10), nullable=False)
|
||||
pokemons_owned = db.Column(db.Integer, default=0)
|
||||
pokemons_list = db.relationship("PokemonOwned", lazy="dynamic")
|
||||
|
||||
def __init__(self, nickname, first_name, last_name, email, password, team):
|
||||
if team not in teams:
|
||||
|
Reference in New Issue
Block a user