def newCloth(shoppingmall_id): session = DBSession() if 'username' not in login_session: return redirect('/login') shoppingmall = session.query(Shoppingmall).filter_by( id=shoppingmall_id).one() if login_session['user_id'] != shoppingmall.user_id: return "<script>function myFunction() {alert('You are not authorized\ to add menu items to this shoppingmall. Please create your own\ shoppingmall model in order to add\ items.');}</script><body onload='myFunction()''>" if request.method == 'POST': newShoppingmall = Cloth( name=request.form['name'], description=request.form['description'], price=request.form['price'], type=request.form['type'], shoppingmall_id=shoppingmall_id, user_id=shoppingmall.user_id) session.add(newShoppingmall) flash('New clothes %s Successfully Created' % (newShoppingmall.name)) session.commit() session.close() return redirect(url_for('showCloth', shoppingmall_id=shoppingmall_id)) else: return render_template('newCloth.html', shoppingmall_id=shoppingmall_id)
def newCloth(): if 'username' not in login_session: return redirect('/login') if request.method == 'POST': newCloth = Cloth(name=request.form['name'], user_id=login_session['user_id']) session.add(newCloth) session.commit() return redirect(url_for('showCloth')) else: return render_template('newCloth.html')
def brandnew(): # code to create a new brand if 'username' not in timelogin: return redirect('/login') if request.method == 'POST': brandnew = Cloth(name=request.form['name'], user_id=timelogin['user_id']) session.add(brandnew) flash('Cloth %s Created' % brandnew.name) session.commit() return redirect( url_for('branddisplay')) # redirect to branddisplay Function else: return render_template('brandnew.html') # move to brandnew.html
def newCloth(shoppingmall_id): session = DBSession() shoppingmall = session.query(Shoppingmall).filter_by( id=shoppingmall_id).one() if 'username' not in login_session: return redirect('/login') if request.method == 'POST': newShoppingmall = Cloth(name=request.form['name'], description=request.form['description'], price=request.form['price'], type=request.form['type'], shoppingmall_id=shoppingmall_id, user_id=shoppingmall.user_id) session.add(newShoppingmall) session.commit() session.close() return redirect(url_for('showCloth', shoppingmall_id=shoppingmall_id)) else: return render_template('newCloth.html', shoppingmall_id=shoppingmall_id) return render_template('newCloth.html')
# database session object. Any change made against the objects in the # session won't be persisted into the database until you call # session.commit(). If you're not happy about the changes, you can # revert all of them back to the last commit by calling # session.rollback() session = DBSession() User1 = User(name="devisri", email="*****@*****.**") session.add(User1) session.commit() shoppingmall1 = Shoppingmall(user_id=1, name="Z_square") session.add(shoppingmall1) session.commit() cloth1 = Cloth(user_id=1, name="Linen", description="ladies dresses", price="$40", type="kurthees", shoppingmall=shoppingmall1) session.add(cloth1) session.commit() cloth2 = Cloth(user_id=1, name="kachi pattu", description="womens ware", type="saries", price="$90", shoppingmall=shoppingmall1) session.add(cloth2) session.commit()
# revert all of them back to the last commit by calling # session.rollback() session = DBSession() # Dummy User User1 = User(name="Saral Kumar", email="*****@*****.**", picture="https://pbs.twimg.com/profile_images/ " "2671170543/18debd694829ed78203a5a36dd364160_400x400.png") session.add(User1) session.commit() # Menu(list of player) for Country India cloth1 = Cloth(name="Kids", user_id=1) session.add(cloth1) session.commit() # Model List info model1 = Model( name="Frock", price="500", color="red", pic= "https://cdn.shopify.com/s/files/1/1083/6796/products/product-image-854828235_1024x1024.jpg?v=1543642880", brand="shein", model_id=1, user_id=1) session.add(model1) session.commit()
# declaratives can be accessed through a DBSession instance Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) # A DBSession() instance establishes all conversations with the database # and represents a "staging zone" for all the objects loaded into the # database session object. Any change made against the objects in the # session won't be persisted into the database until you call # session.commit(). If you're not happy about the changes, you can # revert all of them back to the last commit by calling # session.rollback() session = DBSession() # Menu for UrbanBurger brand = Cloth(user_id=1, name="Adidas") session.add(brand) session.commit() item_1 = Item(user_id=1, name="One Piece", description="Western dress for women", price="$7.50", course="Entree", restaurant=brand) session.add(item_1) session.commit() item_2 = Item(user_id=1, name="Suit", description="Professional Cloths for men", price="Rs.300", course="Appetizer", restaurant=brand) session.add(item_2)