0
我有两个模型CoreDrive和GamificationTechnique以及一个多对多关系的生成表。我试图在表cores_techiques中做一个简单的查询,但总是得到错误。使用烧瓶在sqlalchemy中查询多对多关系时出错
AttributeError:'表'对象没有属性'查询'。
我正在使用python3,flask和sqlalchemy。我很初学,我正在试着用这个应用程序来学习烧瓶。
模型
#many_CoreDrive_has_many_GamificationTechnique
cores_techiques = db.Table('cores_techiques',
db.Column('core_drive_id', db.Integer, db.ForeignKey('core_drive.id')),
db.Column('gamification_technique_id', db.Integer, db.ForeignKey('gamification_technique.id')))
class CoreDrive(db.Model):
id = db.Column(db.Integer(), primary_key=True)
name_core_drive = db.Column(db.String(80), unique=True)
description_core_drive = db.Column(db.String(255))
techniques = db.relationship('GamificationTechnique', secondary=cores_techiques,
backref=db.backref('core_drives', lazy='dynamic'))
class GamificationTechnique(db.Model):
id = db.Column(db.Integer(), primary_key=True)
name_gamification_technique = db.Column(db.String(80), unique=True)
description_gamification_technique = db.Column(db.String(255))
number_gamification_technique = db.Column(db.Integer())
attributtes = db.relationship('Atributte', secondary=techniques_atributtes,
backref=db.backref('gamification_techniques', lazy='dynamic'))
路线
@app.route('/profile')
def profile():
my_core_techique = cores_techiques.query.all()
my_user = User.query.first()
my_technique = GamificationTechnique.query.all()
return render_template('profile.html',my_user=my_user,my_technique=my_technique, my_core_techique=my_core_techique)
您不能创建'my_core_techique = cores_techiques.query.all()',因为cores_techiques是一个Table对象而不是Model对象。你想要传递给页面的内容是什么? –
我需要的数据将在此表 – Ludimila