def item_detail(item_id): item = GroceryItem.query.get(item_id) # TODO: Create a GroceryItemForm and pass in `obj=item` form = GroceryItemForm(obj=item) # TODO: If form was submitted and was valid: # - update the GroceryItem object and save it to the database, # - flash a success message, and # - redirect the user to the item detail page. if form.validate_on_submit(): update_item = GroceryItem(name=form.name.data, price=form.price.data, category=form.category.data, photo_url=form.photo_url.data, store=form.store.data, created_by=current_user) db.session.add(update_item) db.session.commit() flash('Item was updated successfully.') return redirect(url_for('main.item_detail', item_id=update_item.id)) # TODO: Send the form to the template and use it to render the form fields item = GroceryItem.query.get(item_id) return render_template('item_detail.html', item_id=item_id, form=form, item=item)
def new_item(): form = GroceryItemForm() if form.validate_on_submit(): add_item = GroceryItem(name=form.name.data, price=form.price.data, category=form.category.data, photo_url=form.photo_url.data, store=form.store.data, created_by_id=current_user.username) db.session.add(add_item) db.session.commit() flash('Item added') return redirect(url_for('main.item_detail', item_id=add_item.id)) return render_template('new_item.html', form=form)
def new_item(): '''Route for adding a new item to the Database''' form = GroceryItemForm() if form.validate_on_submit(): new_item = GroceryItem(name=form.name.data, price=form.price.data, category=form.category.data, photo_url=form.photo_url.data, store=form.store.data, created_by=current_user, created_by_id=current_user.id) db.session.add(new_item) db.session.commit() flash("New Item was Created!") return redirect(url_for('main.item_detail', item_id=new_item.id)) return render_template('new_item.html', form=form)
def new_item(): form = GroceryItemForm() if form.validate_on_submit(): print("***** trying to print success *****") new_item = GroceryItem(name=form.name.data, price=form.price.data, category=form.category.data, photo_url=form.photo_url.data, store=form.store.data) db.session.add(new_item) db.session.commit() flash('You have Succesfully created a new item') return redirect(url_for('main.item_detail', item_id=new_item.id)) return render_template('new_item.html', form=form)
def new_item(): # Creates a GroceryItemForm form = GroceryItemForm() # If form was submitted and was valid: if form.validate_on_submit(): new_item = GroceryItem(name=form.name.data, price=form.price.data, category=form.category.data, photo_url=form.photo_url.data, store=form.store.data) db.session.add(new_item) db.session.commit() flash('New item was added successfully.') return redirect(url_for('main.item_detail', item_id=new_item.id)) return render_template('new_item.html', form=form)
def new_item(): form = GroceryItemForm() if form.validate_on_submit(): new_item = GroceryItem(name=form.name.data, price=form.price.data, category=form.category.data, photo_url=form.photo_url.data, store=form.store.data) db.session.add(new_item) db.session.commit() flash('Your item has been added!') return redirect(url_for('main.item_detail', item_id=new_item.id)) return render_template('new_item.html', form=form)
def item_detail(item_id): item = GroceryItem.query.get(item_id) form = GroceryItemForm(obj=item) if form.validate_on_submit(): new_item = GroceryItem(name=form.name.data, price=form.price.data, category=form.category.data, photo_url=form.photo_url.data, store=form.store.data) db.session.add(new_item) db.session.commit() flash('Item details were updated successfully.') return redirect(url_for('main.item_detail', item_id=new_item.id)) #Send the form to the template and use it to render the form fields item = GroceryItem.query.get(item_id) return render_template('item_detail.html', item=item, form=form)
def new_item(): #Creates a Newitem form form = GroceryItemForm() if form.validate_on_submit(): new_GroceryItem = GroceryItem( name=form.name.data, price=form.price.data, category=form.category.data, photo_url=form.photo_url.data, store=form.store.data, ) db.session.add(new_GroceryItem) db.session.commit() flash('New GroceryItem was created successfully') return redirect(url_for('main_item_detail')) return render_template('new_item.html', form=form)
def new_item(): # Creating new GroceryItem form = GroceryItemForm() if form.validate_on_submit(): new_GroceryItem = GroceryItem(name=form.name.data, price=form.price.data, category=form.category.data, photo_url=form.photo_url.data, store=form.store.data, created_by=current_user) db.session.add(new_GroceryItem) db.session.commit() flash('New GroceryItem was successfully created') return redirect(url_for('main.item_detail', item_id=new_GroceryItem.id)) return render_template('new_item.html', form=form)
def new_item(): form = GroceryItemForm() if form.validate_on_submit(): new_i = GroceryItem(name=form.name.data, price=form.price.data, category=form.category.data, photo_url=form.photo_url.data, store=form.store.data) db.session.add(new_i) db.session.commit() flash('New item was created successfully.') # - redirect the user to the store detail page. return redirect(url_for('main.item_detail', GroceryItem_id=new_i.id)) # Send the form to the template and use it to render the form fields return render_template('new_item.html', form=form)
def new_item(): groceryItemForm = GroceryItemForm() if groceryItemForm.validate_on_submit(): print('safdas') # Create new ORM GroceryItem newGroceryItem = GroceryItem(name=groceryItemForm.name.data, price=groceryItemForm.price.data, category=groceryItemForm.category.data, photo_url=groceryItemForm.photo_url.data, store=groceryItemForm.store.data, created_by=current_user) db.session.add(newGroceryItem) db.session.commit() flash('Success') # Send to created GroceryItem page return redirect(url_for('main.item_detail', item_id=newGroceryItem.id)) # Returned on 'GET' return render_template('new_item.html', groceryItemForm=groceryItemForm, current_user=current_user)
def item_detail(item_id): item = GroceryItem.query.get(item_id) form = GroceryItemForm(obj=item) if form.validate_on_submit(): new_GroceryItem = GroceryItem( name=form.name.data, price=form.price.data, category=form.category.data, photo_url=form.photo_url.data, store=form.store.data, ) db.session.add(new_GroceryItem) db.session.commit() flash('New GroceryItem was created successfully') return redirect(url_for('main.item_detail', item_id=new_GroceryItem.id)) item = GroceryItem.query.get(item_id) return render_template('item_detail.html', item=item)
def new_item(): # Creates a GroceryItemForm form = GroceryItemForm() # If form was submitted and was valid: # - create a new GroceryItem object and save it to the database, # - flash a success message, and # - redirect the user to the item detail page. if form.validate_on_submit(): new_item = GroceryItem(name=form.name.data, price=form.price.data, category=form.category.data, photo_url=form.photo_url.data, store=form.store.data) db.session.add(new_item) db.session.commit() flash('New item added') return redirect(url_for('main.item_detail', item_id=new_item.id)) return render_template('new_item.html', form=form)
def new_item(): # TODO: Create a GroceryItemForm form = GroceryItemForm() # TODO: If form was submitted and was valid: # - create a new GroceryItem object and save it to the database, # - flash a success message, and # - redirect the user to the item detail page. if form.validate_on_submit(): new_item = GroceryItem(name=form.name.data, price=form.price.data, category=form.category.data, photo_url=form.photo_url.data, store=form.store.data, created_by=current_user) db.session.add(new_item) db.session.commit() flash('Item was created successfully.') return redirect(url_for('main.item_detail', item_id=new_item.id)) # TODO: Send the form to the template and use it to render the form fields return render_template('new_item.html', form=form)
def new_item(): # Creates a GroceryItemForm form = GroceryItemForm() if form.validate_on_submit(): # - creates a new GroceryItem object and save it to the database, new_GroceryItem = GroceryItem( name=form.name.data, price=form.price.data, category=form.category.data, photo_url=form.photo_url.data, store=form.store.data, created_by=current_user ) db.session.add(new_GroceryItem) db.session.commit() # - flash a success message, and flash('You have successfully added a new grocery item!') # - redirect the user to the item detail page. return redirect(url_for('main.item_detail', item_id=new_GroceryItem.id)) return render_template('new_item.html', form=form)