Пример #1
0
class Spaceship(db.Model):
    __tablename__ = "Spaceship"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)

    def __init__(self, name):
        self.name = name
Пример #2
0
class Alien(db.Model):
    __tablename__ = "Alien"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)

    def __init__(self, name):
        self.name = name

    def get_killer_id(self):  # return -1 if alien if alive
        if self.cemetery is not None:
            return self.cemetery.killer_id
        else:
            return -1
Пример #3
0
class Experiment(db.Model):
    __tablename__ = "Experiment"
    id = db.Column(db.Integer, primary_key=True)
    date = db.Column(db.DateTime, default=datetime.utcnow)
    human_id = db.Column(db.Integer, db.ForeignKey("Human.id"), nullable=False)
    spaceship_id = db.Column(db.Integer, db.ForeignKey("Spaceship.id"), nullable=False)
    human = db.relationship("Human", backref=db.backref("experiments", lazy=True))
    aliens = db.relationship("Alien", secondary=experiment_aliens, backref=db.backref("experiments", lazy=True))
    spaceship = db.relationship("Spaceship", backref=db.backref("experiments", lazy=True))

    def __init__(self, human, alien, spaceship):
        self.human = human
        self.alien = alien
        self.spaceship = spaceship
Пример #4
0
class Escape(db.Model):
    __tablename__ = "Escape"
    id = db.Column(db.Integer, primary_key=True)
    date = db.Column(db.DateTime, default=datetime.utcnow)
    human_id = db.Column(db.Integer, db.ForeignKey("Human.id"), nullable=False)
    spaceship_id = db.Column(db.Integer,
                             db.ForeignKey("Spaceship.id"),
                             nullable=False)
    human = db.relationship("Human", backref=db.backref("escapes", lazy=True))
    spaceship = db.relationship("Spaceship",
                                backref=db.backref("escapes", lazy=True))

    def __init__(self, human, spaceship):
        self.human = human
        self.spaceship = spaceship
Пример #5
0
class Excursion(db.Model):
    __tablename__ = "Excursion"
    id = db.Column(db.Integer, primary_key=True)
    date = db.Column(db.DateTime, default=datetime.utcnow)
    alien_id = db.Column(db.Integer, db.ForeignKey("Alien.id"), nullable=False)
    guide = db.relationship("Alien",
                            backref=db.backref("excursions", lazy=True))
    participants = db.relationship("Human",
                                   secondary=excursion_humans,
                                   backref=db.backref("excursions", lazy=True))

    def __init__(self, human, alien, spaceship):
        self.human = human
        self.alien = alien
        self.spaceship = spaceship
Пример #6
0
class Cemetery(db.Model):
    __tablename__ = "Cemetery"
    id = db.Column(db.Integer, primary_key=True)
    date = db.Column(db.DateTime, default=datetime.utcnow)
    killer_id = db.Column(db.Integer,
                          db.ForeignKey("Human.id"),
                          nullable=False)
    alien_id = db.Column(db.Integer, db.ForeignKey("Alien.id"), nullable=False)
    killer = db.relationship("Human", backref=db.backref("killed", lazy=True))
    alien = db.relationship("Alien",
                            backref=db.backref("cemetery",
                                               lazy=True,
                                               uselist=False))

    def __init__(self, human, alien):
        self.human = human
        self.alien = alien
Пример #7
0
class Commutation(db.Model):
    __tablename__ = "Commutation"
    id = db.Column(db.Integer, primary_key=True)
    date = db.Column(db.DateTime, default=datetime.utcnow)
    human_id = db.Column(db.Integer, db.ForeignKey("Human.id"), nullable=False)
    alien_id = db.Column(db.Integer, db.ForeignKey("Alien.id"), nullable=False)
    from_id = db.Column(db.Integer, db.ForeignKey("Spaceship.id"), nullable=False)
    to_id = db.Column(db.Integer, db.ForeignKey("Spaceship.id"), nullable=False)
    from_ship = db.relationship("Spaceship", backref=db.backref("transferred", lazy=True), foreign_keys=[from_id])
    to_ship = db.relationship("Spaceship", backref=db.backref("accepted", lazy=True), foreign_keys=[to_id])
    human = db.relationship("Human", backref=db.backref("commutations", lazy=True))
    alien = db.relationship("Alien", backref=db.backref("commutations", lazy=True))

    def __init__(self, human, alien, frm, to):
        self.human = human
        self.alien = alien
        self.frm = frm
        self.to = to
Пример #8
0
from aliens import db
from datetime import datetime


experiment_aliens = db.Table('ExperimentAliens',
    db.Column('experiment_id', db.Integer, db.ForeignKey('Experiment.id'), primary_key=True),
    db.Column('alien_id', db.Integer, db.ForeignKey('Alien.id'), primary_key=True)
)

class Experiment(db.Model):
    __tablename__ = "Experiment"
    id = db.Column(db.Integer, primary_key=True)
    date = db.Column(db.DateTime, default=datetime.utcnow)
    human_id = db.Column(db.Integer, db.ForeignKey("Human.id"), nullable=False)
    spaceship_id = db.Column(db.Integer, db.ForeignKey("Spaceship.id"), nullable=False)
    human = db.relationship("Human", backref=db.backref("experiments", lazy=True))
    aliens = db.relationship("Alien", secondary=experiment_aliens, backref=db.backref("experiments", lazy=True))
    spaceship = db.relationship("Spaceship", backref=db.backref("experiments", lazy=True))

    def __init__(self, human, alien, spaceship):
        self.human = human
        self.alien = alien
        self.spaceship = spaceship
Пример #9
0
from aliens import db
from datetime import datetime

excursion_humans = db.Table(
    'ExcursionHuman',
    db.Column('excursion_id',
              db.Integer,
              db.ForeignKey('Excursion.id'),
              primary_key=True),
    db.Column('human_id',
              db.Integer,
              db.ForeignKey('Human.id'),
              primary_key=True))


class Excursion(db.Model):
    __tablename__ = "Excursion"
    id = db.Column(db.Integer, primary_key=True)
    date = db.Column(db.DateTime, default=datetime.utcnow)
    alien_id = db.Column(db.Integer, db.ForeignKey("Alien.id"), nullable=False)
    guide = db.relationship("Alien",
                            backref=db.backref("excursions", lazy=True))
    participants = db.relationship("Human",
                                   secondary=excursion_humans,
                                   backref=db.backref("excursions", lazy=True))

    def __init__(self, human, alien, spaceship):
        self.human = human
        self.alien = alien
        self.spaceship = spaceship