def create_db(): try: User.drop_table() Member.drop_table() Commodity.drop_table() Category.drop_table() UserOrder.drop_table() OrderItem.drop_table() CommodityImage.drop_table() CommodityComment.drop_table() Address.drop_table() OrderStatus.drop_table() Announcement.drop_table() Feedback.drop_table() except: pass User.create_table() Member.create_table() Commodity.create_table() Category.create_table() UserOrder.create_table() OrderItem.create_table() CommodityImage.create_table() CommodityComment.create_table() Address.create_table() OrderStatus.create_table() Announcement.create_table() Feedback.create_table()
def random_co(): global category_list global co_list name = " ".join(random_name(1)) co = Commodity.create(price=random.randint(20, 100), name=name, category=random.choice(category_list)) CommodityImage.create(name=random_img(), commodity=co) co_list.append(co) return co
def image_upload(com_id): datafile = request.files['file'] filename = datafile.filename path = "/".join(['./static/img/commodity', filename]) url = "/".join(['/static/img/commodity', filename]) commodity = get_object_or_404(Commodity, id=com_id) img = CommodityImage.create(name=filename, commodity=commodity) datafile.save(path) return jsonify(success=True, url=url, img_id=img.id)