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