Blockchain_KM/app/models.py
2024-12-02 01:18:08 +08:00

44 lines
1.9 KiB
Python

from app import db
subtopic_keywords = db.Table('subtopic_keywords',
db.Column('subtopic_id', db.Integer, db.ForeignKey('subtopic.id', ondelete='CASCADE'),
primary_key=True),
db.Column('keyword_id', db.Integer, db.ForeignKey('keyword.id', ondelete='CASCADE'),
primary_key=True)
)
class Section(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100), nullable=False)
order_num = db.Column(db.Integer, nullable=False)
topics = db.relationship('Topic', backref='section', lazy=True,
cascade='all, delete-orphan')
class Topic(db.Model):
id = db.Column(db.Integer, primary_key=True)
section_id = db.Column(db.Integer, db.ForeignKey('section.id', ondelete='CASCADE'), nullable=False)
title = db.Column(db.String(200), nullable=False)
description = db.Column(db.Text)
subtopics = db.relationship('Subtopic', backref='topic', lazy=True,
cascade='all, delete-orphan')
class Subtopic(db.Model):
id = db.Column(db.Integer, primary_key=True)
topic_id = db.Column(db.Integer, db.ForeignKey('topic.id', ondelete='CASCADE'), nullable=False)
title = db.Column(db.String(200), nullable=False)
content = db.Column(db.Text)
keywords = db.relationship('Keyword',
secondary=subtopic_keywords,
lazy='subquery',
backref=db.backref('subtopics', lazy=True, passive_deletes=True),
passive_deletes=True)
class Keyword(db.Model):
id = db.Column(db.Integer, primary_key=True)
term = db.Column(db.String(100), nullable=False, unique=True)
description = db.Column(db.Text, nullable=False)