def admin_product(): if not session.get("login", False): return redirect(url_for("login")) form = ProductForm(request.form) current_app.logger.info("vali:" + str(form.validate())) if request.method == "POST" and form.validate(): current_app.logger.info("true") prod = Product(form.title.data, form.image.data, form.price.data, form.price2.data, form.content.data) db.session.add(prod) db.session.commit() db.session.add( Product_Attr( prod.id, request.form["code1"], request.form["code2"], request.form["code3"], request.form["factory_name"], request.form["factory_addr"], request.form["factory_phone"], request.form["ingredients"], request.form["net_weight"], request.form["store_way"], request.form["origine"], request.form["shief_life"], request.form["food_addiitive"], request.form["packing"], request.form["brand"], request.form["series"], request.form["weight"], request.form["kind"], request.form["grade"], request.form["plucking_time"], request.form["growing_season"], request.form["organic_food"], ) ) db.session.commit() return render_template("admin_product_insert.html")
def admin_product_update(pid): if not session.get("login", False): return redirect(url_for("login")) product = Product.query.filter(Product.id == pid).first() form = ProductForm(request.form) if request.method == "POST" and form.validate(): product.title = form.title.data product.content = form.content.data product.image = form.image.data product.price = form.price.data db.session.merge(product) db.session.commit() return render_template("admin_product_update.html", product=product)