0

I have two models CoreDrive and GamificationTechnique and a generated table of a many-to-many relationship. I'm trying to do a simple query in table cores_techiques , but always get the error.

AttributeError: 'Table' object has no attribute 'query'.

I'm using python3, flask and sqlalchemy. I'm very beginner, I'm trying to learn flask with this application.

Models

#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'))

Routes

@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)
2
  • you cannot make my_core_techique = cores_techiques.query.all() because cores_techiques is a Table object not a Model object. What you want to pass to the page exactly? Commented Sep 29, 2016 at 2:27
  • I need the data that will be in this table Commented Oct 6, 2016 at 20:14

1 Answer 1

1

You can list all the CoreDriver and each object have a list of the GamificationTechnique

cores = CoreDrivers.query.all()
for core in cores:
    print core.techniques

With this in mind you can spend only the list cores to page

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.