qboard = Board.query.filter_by(timber_id=ID).all()
qboard = Board.query.all()
models.py
class Board(db.Model): id = db.Column(db.Integer, primary_key=True) wh = db.Column(db.Integer) ht = db.Column(db.Integer) timber_id = db.Column(db.Integer, db.ForeignKey("timber.id")) class Timber(db.Model): id = db.Column(db.Integer, primary_key=True) diam = db.Column(db.Integer) boards = db.relationship("Board", backref = 'timber')
class AddForm(Form): chdiam = SelectField("timber", choices=[]) chboard = SelectField("board", choices=[]) count = TextField("count")
@app.route('/add', methods = ['GET', 'POST']) def add(): qtimber = Timber.query.all() tchoices = [(timber.id, timber.diam) for timber in qtimber] qboard = Board.query.all() bchoices = [(board.id, str(board.wh )+"x"+str(board.ht)) for board in qboard] form = AddForm() form.chdiam.choices = tchoices form.chboard.choices = bchoices return render_template('add.html', form = form)