Ejemplo n.º 1
0
class Character(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(150))
    description = db.Column(db.String(200))
    comics_appeared_in = db.Column(db.Integer)
    super_power = db.Column(db.String(150))
    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    user_id = db.Column(db.String, db.ForeignKey('user.token'), nullable=False)

    def __init__(self, name, description, comics_appeared_in, super_power,
                 user_id):
        self.name = name
        self.description = description
        self.comics_appeared_in = comics_appeared_in
        self.super_power = super_power
        self.user_id = user_id

    def __repr__(self):
        return f'The following Character has been added: {self.name} which belongs to {self.user_id}'

    def to_dict(self):
        return {
            "id": self.id,
            "name": self.name,
            "description": self.description,
            "comics_appeared_in": self.comics_appeared_in,
            "super_power": self.super_power
        }
Ejemplo n.º 2
0
class Marvel(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(150))
    description = db.Column(db.String(150))
    comics_appeared_in = db.Column(db.Integer)
    super_power = db.Column(db.String(150))
    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    owner = db.Column(db.String, db.ForeignKey('user.token'), nullable=False)
    character = db.Column(db.String(150))

    def __init__(self, name, description, comics_appeared_in, super_power,
                 owner, character):

        self.name = name
        self.description = description
        self.comics_appeared_in = comics_appeared_in
        self.super_power = super_power
        self.owner = owner
        self.character = character

    def set_id(self):
        return str(uuid.uuid4())

    def __repr__(self):
        return f'The following Marvel has been added {self.name}'

    def __str__(self):
        return f"{self.name}\n\nDescription:\n{self.description}\n\nSuperpowers:\n{self.super_power}"

    def to_dict(self):
        return {
            "id": self.id,
            "name": self.name,
            "description": self.description,
            "comics_appeared_in": self.comics_appeared_in,
            "super_power": self.super_power,
            "date_created": self.date_created,
            "character": self.character
        }
Ejemplo n.º 3
0
class Character(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    current_alias = db.Column(db.String(150), nullable=False)
    real_name = db.Column(db.String(150), nullable=True, default='')
    origin = db.Column(db.String(150), nullable=True, default='')
    universe = db.Column(db.String(150), nullable=True, default='')
    power = db.Column(db.String(150), nullable=True, default='')
    comics_appeared_in = db.Column(db.Integer, nullable=True, default=0)
    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    user_id = db.Column(db.String, db.ForeignKey('user.token'), nullable=False)

    def __init__(self, current_alias, real_name, origin, universe, power,
                 comics_appeared_in, user_id):
        self.current_alias = current_alias
        self.real_name = real_name
        self.origin = origin
        self.universe = universe
        self.power = power
        self.comics_appeared_in = comics_appeared_in
        self.user_id = user_id

    def __repr__(self):
        return self.current_alias

    def to_dict(self):
        return {
            "id": self.id,
            "current_alias": self.current_alias,
            "real_name": self.real_name,
            "origin": self.origin,
            "universe": self.universe,
            "power": self.power,
            "comics_appeared_in": self.comics_appeared_in,
            "date_created": self.date_created,
        }