예제 #1
0
파일: work.py 프로젝트: gitzx/React-Flask
class Work(db.Model):
    """作品"""
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(50))
    title_suffix = db.Column(db.String(50))  # 完整的标题,用于没有题目的词,使用第一个短句作为其题目
    foreword = db.Column(db.Text())
    content = db.Column(db.Text())
    intro = db.Column(db.Text())
    layout = db.Column(db.String(10))
    highlight = db.Column(db.Boolean, default=False)
    create_time = db.Column(db.DateTime, default=datetime.datetime.now)
    updated_at = db.Column(db.DateTime, default=datetime.datetime.now)
    highlight_at = db.Column(db.DateTime)

    author_id = db.Column(db.Integer, db.ForeignKey('author.id'))
    author = db.relationship('Author',
                             backref=db.backref('works', lazy='dynamic'))

    type_id = db.Column(db.Integer, db.ForeignKey('work_type.id'))
    type = db.relationship('WorkType',
                           backref=db.backref('works', lazy='dynamic'))

    @property
    def full_title(self):
        if self.title_suffix and '·' not in self.title:
            return "%s · %s" % (self.title, self.title_suffix)
        else:
            return self.title

    def __repr__(self):
        return '<Work %s>' % self.title
예제 #2
0
class Collection(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    order = db.Column(db.Integer, default=0)
    name = db.Column(db.String(200), unique=True)
    full_name = db.Column(db.String(200), unique=True)
    desc = db.Column(db.Text())
    cover = db.Column(db.String(200))
    link = db.Column(db.String(300))
    abbr = db.Column(db.String(50))
    created_at = db.Column(db.DateTime, default=datetime.now)
    kind_id = db.Column(db.Integer, db.ForeignKey('collection_kind.id'))
    kind = db.relationship('CollectionKind',
                           backref=db.backref(
                               'collections',
                               lazy='dynamic',
                               order_by="asc(Collection.order)"))

    @property
    def max_work_order(self):
        if self.works.count() == 0:
            return 0
        return CollectionWork.query.filter(CollectionWork.collection_id == self.id). \
            order_by(CollectionWork.order.desc()).first().order

    def __repr__(self):
        return '<Collection %s>' % self.name
예제 #3
0
파일: work.py 프로젝트: gitzx/React-Flask
class WorkType(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    en = db.Column(db.String(50))
    cn = db.Column(db.String(50))

    def __repr__(self):
        return '<WorkType %s>' % self.cn
예제 #4
0
class Dynasty(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))
    intro = db.Column(db.Text())
    start_year = db.Column(db.Integer)
    end_year = db.Column(db.Integer)

    def __repr__(self):
        return '<Dynasty %s>' % self.name
예제 #5
0
class CollectionKind(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    order = db.Column(db.Integer, default=0)
    name = db.Column(db.String(50), unique=True)
    created_at = db.Column(db.DateTime, default=datetime.now)

    @property
    def max_collection_order(self):
        if self.collections.count() == 0:
            return 0
        return Collection.query.filter(Collection.kind_id == self.id). \
            order_by(Collection.order.desc()).first().order
예제 #6
0
파일: author.py 프로젝트: gitzx/React-Flask
class Author(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))
    intro = db.Column(db.Text())
    birth_year = db.Column(db.String(20))
    death_year = db.Column(db.String(20))
    updated_at = db.Column(db.DateTime, default=datetime.datetime.now)

    dynasty_id = db.Column(db.Integer, db.ForeignKey('dynasty.id'))
    dynasty = db.relationship('Dynasty',
                              backref=db.backref(
                                  'authors',
                                  lazy='dynamic',
                                  order_by="asc(Author.birth_year)"))

    def __repr__(self):
        return '<Author %s>' % self.name

    @property
    def random_quote(self):
        """Get a random quote of the author"""
        return self.quotes.order_by(db.func.random()).first()
예제 #7
0
파일: work.py 프로젝트: gitzx/React-Flask
class WorkImage(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    filename = db.Column(db.String(200))
    is_original = db.Column(db.Boolean, default=False)
    from_url = db.Column(db.String(250))
    create_time = db.Column(db.DateTime, default=datetime.datetime.now)

    work_id = db.Column(db.Integer, db.ForeignKey('work.id'))
    work = db.relationship('Work',
                           backref=db.backref('images', lazy='dynamic'))

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User',
                           backref=db.backref(
                               'work_images',
                               lazy='dynamic',
                               order_by="desc(WorkImage.create_time)"))

    @property
    def url(self):
        return current_app.config['OSS_URL'] + self.filename

    def __repr__(self):
        return '<WorkImage %s>' % self.filename
예제 #8
0
class Topic(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100))
    content = db.Column(db.Text)
    click_num = db.Column(db.Integer, default=0)
    create_time = db.Column(db.DateTime, default=datetime.datetime.now)

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User',
                           backref=db.backref(
                               'topics',
                               lazy='dynamic',
                               order_by="desc(Topic.create_time)"))

    def __repr__(self):
        return '<Topic %s>' % self.title
예제 #9
0
파일: work.py 프로젝트: gitzx/React-Flask
class WorkReview(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100))
    content = db.Column(db.Text)
    is_publish = db.Column(db.Boolean)
    click_num = db.Column(db.Integer, default=0)
    create_time = db.Column(db.DateTime, default=datetime.datetime.now)

    work_id = db.Column(db.Integer, db.ForeignKey('work.id'))
    work = db.relationship('Work',
                           backref=db.backref(
                               'reviews',
                               lazy='dynamic',
                               order_by="desc(WorkReview.create_time)"))

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User',
                           backref=db.backref(
                               'work_reviews',
                               lazy='dynamic',
                               order_by="desc(WorkReview.create_time)"))

    def __repr__(self):
        return '<WorkReview %s>' % self.title