def admin_products(): if not g.user: return redirect('/') else: products = Product.query.all() form = ProductForm() #add product to db if form.validate_on_submit(): product = Product.form_to_model(form) #converting images into bytes like object #prepare images to be stored product.prepare_to_store() db.session.add(product) db.session.commit() flash('Product added to database', 'success') return redirect(f'/{get_route()}/view-products') else: for product in products: if product.available: product.availabile = 'Available' else: product.availabile = 'Sold' for product in products: product.prepare_to_show() organized_products = Helper.organize_products(products) return render_template('view-products.html', form=form, rows=organized_products, route=get_route())
def return_products_page(): products = Product.query.filter_by(available=True).all() for product in products: product.prepare_to_show() for product in products: product.available = 'Available' organized_products = Helper.organize_products(products) return render_template('products2.html', rows=organized_products)
def show_gallery(): products = Product.query.filter_by(available=False).all() for product in products: product.prepare_to_show() organized_products = Helper.organize_products(products) return render_template('gallery.html', rows=organized_products)