Пример #1
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    author = db.Column(db.String(50), default='shengyu')
    pub_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    category_id = db.Column(db.Integer,
                            db.ForeignKey('category.id'),
                            nullable=False)
    category = db.relationship('Category', backref='post', lazy=True)
Пример #2
0
class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(128), unique=True, index=True)
    password_hash = db.Column(db.String(128))

    def set_password(self, password):
        self.password_hash = generate_password_hash(password)

    def validate_password(self, password):
        return check_password_hash(self.password_hash, password)
Пример #3
0
class Planet(db.Model, CRUDMixin):
    __endpoint__ = "planets"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)

    def __repr__(self):
        return self.name

    @classmethod
    def search_by_name(cls, name):
        return cls.query.filter_by(name=name)
Пример #4
0
class Film(db.Model, CRUDMixin):
    __endpoint__ = "films"

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)

    def __repr__(self):
        return self.title

    @classmethod
    def search_by_title(cls, title):
        return cls.query.filter_by(title=title)
Пример #5
0
class Person(db.Model, CRUDMixin):
    __endpoint__ = "people"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    birth_year = db.Column(db.String(100), nullable=False)
    eye_color = db.Column(db.String(100), nullable=False)
    gender = db.Column(db.String(100), nullable=False)
    hair_color = db.Column(db.String(100), nullable=False)
    height = db.Column(db.String(100), nullable=False)
    mass = db.Column(db.String(100), nullable=False)
    skin_color = db.Column(db.String(100), nullable=False)
    created = db.Column(db.String(100), nullable=False)
    edited = db.Column(db.String(100), nullable=False)

    homeworld_id = db.Column(
        db.Integer, db.ForeignKey("planet.id"), nullable=False)
    homeworld = db.relationship(
        "Planet", backref=db.backref("people", lazy=True))

    films = db.relationship(
        "Film", secondary=films, lazy="subquery", backref=db.backref("people", lazy=True)
    )
    starships = db.relationship(
        "Starship", secondary=starships, lazy="subquery", backref=db.backref("people", lazy=True)
    )
    vehicles = db.relationship(
        "Vehicle", secondary=vehicles, lazy="subquery", backref=db.backref("people", lazy=True)
    )

    def __repr__(self):
        return self.name

    @classmethod
    def search_by_name(cls, name):
        return cls.query.filter_by(name=name)
Пример #6
0
class Links(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    site = db.Column(db.String(50), nullable=False)
    url = db.Column(db.String(200), nullable=False)
Пример #7
0
class Category(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
Пример #8
0
class Starship(db.Model, CRUDMixin):
    __endpoint__ = "starships"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    model = db.Column(db.String(100), nullable=False)
    starship_class = db.Column(db.String(100), nullable=False)
    manufacturer = db.Column(db.String(100), nullable=False)
    cost_in_credits = db.Column(db.String(100), nullable=False)
    length = db.Column(db.String(100), nullable=False)
    crew = db.Column(db.String(100), nullable=False)
    passengers = db.Column(db.String(100), nullable=False)
    max_atmosphering_speed = db.Column(db.String(100), nullable=False)
    hyperdrive_rating = db.Column(db.String(100), nullable=False)
    mglt = db.Column(db.String(100), nullable=False)
    cargo_capacity = db.Column(db.String(100), nullable=False)
    consumables = db.Column(db.String(100), nullable=False)
    created = db.Column(db.String(100), nullable=False)
    edited = db.Column(db.String(100), nullable=False)
    score = db.Column(db.String(100), nullable=False)

    films = db.relationship(
        "Film", secondary=films_starships, lazy="subquery", backref=db.backref("starships", lazy=True)
    )

    def __repr__(self):
        return self.name

    @classmethod
    def search_by_name(cls, name):
        return cls.query.filter_by(name=name)