def new_item_save(): """ saves the new item to db """ form = request.form item = Item() item.category_id = int(form['category']) item.title = form['title'] item.description = form['description'] item.created_at = datetime.now() item.user_id = current_user.id db.session.add(item) db.session.commit() return redirect(url_for('index'))
def item_create(category_id): """ This creates a new item only if the user is logged in """ if not logged_in(): flash('Please log in to create items') return redirect(url_for('category_list')) form = ItemForm() if form.validate_on_submit(): item = Item() item.title = form.title.data item.description = form.description.data item.category_id = category_id item.ctlg_user = get_current_user() db.session.add(item) db.session.commit() return redirect(url_for('item_create', category_id=category_id)) return render_template('item_create.html', form=form, category_id=category_id)
print "User - Sophie Reddimalla created ID=" + str(user.id) print "Creating Sample Category Football ..." category = Category() category.title = "Football" category.user_id = user.id category.created = datetime.utcnow() category.modified = datetime.utcnow() db.session.add(category) db.session.commit() print "Category - Football created ID=" + str(category.id) print "Creating Sample Items in Football ..." item = Item() item.category_id = category.id item.title = "Soccer Ball" item.description = "High Quality ,Tournament grade" item.created = datetime.utcnow() item.modified = datetime.utcnow() item.user_id = user.id db.session.add(item) db.session.commit() print "Item - %s created ID=%d" % (item.title, item.id) print "Creating Sample Items in Football ..." item = Item() item.category_id = category.id item.title = "Studs - Reebok" item.description = "Imported Studs from Taiwan" item.created = datetime.utcnow() item.modified = datetime.utcnow()