1 回答

TA貢獻(xiàn)1830條經(jīng)驗 獲得超9個贊
我發(fā)現(xiàn)出了什么問題,我沒有在移動表中設(shè)置product_id 的值。
if form.validate_on_submit():
product = Product.query.filter_by(id=form.product.data).first()
from_location = Location.query.filter_by(id=form.from_location.data).first()
to_location = Location.query.filter_by(id=form.to_location.data).first()
m = Movement(product_id = product.id, product = product.name, from_location_id = from_location.id, from_location = from_location.name, to_location_id = to_location.id, to_location = to_location.name, quantity = form.quantity.data)
db.session.add(m)
db.session.commit()
movements = Movement.query.all()
products = Product.query.all()
locations = Location.query.all()
return render_template('movements.html', movements=movements, products=products, locations=locations, form=form)
現(xiàn)在可以了。
添加回答
舉報