我正在创建一个应用程序来替换浏览器中当前的选项卡管理器。我在组 - 表主题和选项卡 - 表选项卡之间创建了一个简单的一对多关系。我希望在删除主题时能够自动删除它的子主题。这就是我目前所拥有的:
from flask import request, redirect, url_for, render_template, Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import exc
from flask_whooshee import Whooshee
from datetime import datetime
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
whooshee = Whooshee(app)
@whooshee.register_model('topic_name')
class Topic(db.Model):
__tablename__ = 'topic'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
topic_name = db.Column(db.String, unique=True, nullable=False)
topic_created = db.Column(db.DateTime, default=datetime.utcnow)
topic_changed = db.Column(db.DateTime, default=datetime.utcnow)
topic_tabs = db.relationship('Tab', backref='topic', cascade='all, delete-orphan', lazy='dynamic')
@whooshee.register_model('tab_name', 'tab_link', 'tab_description')
class Tab(db.Model): …Run Code Online (Sandbox Code Playgroud)