[英]Error in query many-to-many relationship in sqlalchemy using flask
我有兩個模型CoreDrive和GamificationTechnique,以及一個生成的多對多關系表。 我正在嘗試在表cores_techiques中執行一個簡單的查詢,但總是會收到錯誤。
AttributeError:“表”對象沒有屬性“查詢”。
我正在使用python3,flask和sqlalchemy。 我是一個非常初學者,我正在嘗試使用此應用程序學習flask。
楷模
#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)
您可以列出所有CoreDriver
並且每個對象都有GamificationTechnique
的列表
cores = CoreDrivers.query.all()
for core in cores:
print core.techniques
考慮到這一點,您只能將列表cores
花費在頁面上
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.