多级分类
from flask import *
from flask_sqlalchemy import SQLAlchemy
app = Flask(name)
app.secret_key = ‘1812B’
app.config[‘SQLALCHEMY_DATABASE_URI’] = ‘mysql+pymysql://root:[email protected]:3306/shop?charset=utf8’
app.config[‘SQLALCHEMY_TRACK_MODIFICATIONS’] = True
db = SQLAlchemy(app)
分类1
class BigCategory(db.Model):
tablename = ‘bigcategory’
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(200), unique=True, nullable=False)
small_list = db.relationship(‘SmallCategory’, backref=‘big’)
分类2
class SmallCategory(db.Model):
tablename = ‘smallcategory’
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(200), nullable=False)
big_id =