def get(self): categories = [] result = Categories.get_all() for category in result: categories.append(category.toDict()) self.write({'categories': categories})
def addCatagory(category): """two helper functions that extract data from DBSampleData.py""" """and fill the corresponding tables""" for i in category: categories = Categories(name=i) session.add(categories) session.commit
def newcategories(): if 'username' not in login_session: return redirect('/login') if request.method == 'POST': newcategories = Categories(name=request.form['name'], user_id=login_session['user_id']) session.add(newcategories) flash('New Categorie %s Successfully Created' % newcategories.name) session.commit() return redirect(url_for('showcategories')) else: return render_template('newcategories.html')
def AddNewItem(supermart_category_id): if 'username' not in login_session: return redirect('/login') if request.method == 'POST': newCategoryItem = Categories( name=request.form['name'], description=request.form['description'], price=request.form['price'], offer=request.form['offer'], supermart_category_id=supermart_category_id, user_id=login_session["user_id"]) session.add(newCategoryItem) session.commit() return redirect( url_for('ShowCategory', supermart_category_id=supermart_category_id)) else: return render_template('newitem.html', supermart_category_id=supermart_category_id)
engine = create_engine('sqlite:///datamenu.db') #engine = create_engine('postgresql://*****:*****@localhost/catalog') Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() #Create first user User1 = User(name="Ankit Singh", email="[email protected]") session.add(User1) session.commit() cat = Categories(user_id=1, name="Soccor") session.add(cat) session.commit() Litem1 = Items( user_id=1, name="Shinguards", description= " A shin guard or shin pad is a piece of equipment worn on the front of a players shin to protect them from injury. These are commonly used in sports including association football, baseball, ice hockey, field hockey, lacrosse, cricket, and other sports. This is due to either being required by the rules and laws of the sport or worn voluntarily by the participants for protective measures!!", categories=cat) session.add(Litem1) session.commit() Litem1 = Items(
from sqlalchemy.orm import sessionmaker from database import Base, Categories, Items, Users engine = create_engine('sqlite:///itemcatalog.db') Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() # Create dummy user User1 = Users(name="Robo Barista", email="*****@*****.**") session.add(User1) session.commit() # Categories for the catalog soccer = Categories(name="Soccer", user_id=1) session.add(soccer) session.commit() basketball = Categories(name="Basketball", user_id=1) session.add(basketball) session.commit() baseball = Categories(name="Baseball", user_id=1) session.add(baseball) session.commit() frisbee = Categories(name="Frisbee", user_id=1) session.add(frisbee) session.commit()
def get(self): category = self.get_argument('category') ctg = Categories(category) Categories.add(ctg)