1 回答
TA贡献1830条经验 获得超9个赞
我发现出了什么问题,我没有在移动表中设置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)
现在可以了。
添加回答
举报