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 item_detail(item_id): """Display grocery item details with update form below.""" item = GroceryItem.query.get(item_id) # Create a GroceryItemForm and pass in `obj=item` form = GroceryItemForm(obj=item) # 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(): item.name = form.name.data item.price = form.price.data item.category = form.category.data item.photo_url = form.photo_url.data item.store = form.store.data db.session.add(item) db.session.commit() flash('The grocery item was updated successfully.') return redirect(url_for('main.item_detail', item_id=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 item_detail(item_id): item = GroceryItem.query.get(item_id) form = GroceryItemForm(obj=item) if form.validate_on_submit(): form.populate_obj(item) db.session.add(item) db.session.commit() flash("Item was successfully updated.") return redirect(url_for('main.item_detail', item_id=item.id)) return render_template('item_detail.html', item=item, form=form)
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 item_detail(item_id): item = GroceryItem.query.get(item_id) form = GroceryItemForm(obj=item) if form.validate_on_submit(): item.name = form.name.data item.price = form.price.data item.category = form.category.data item.photo_url = form.photo_url.data item.store = form.store.data db.session.commit() flash('Item updated') return redirect(url_for('main.item_detail', item_id=item.id, item=item)) return render_template('item_detail.html', item=item, form=form)
def item_detail(item_id): '''Route for displaying and modifying a items information in the database.''' item = GroceryItem.query.get(item_id) form = GroceryItemForm(obj=item) if form.validate_on_submit(): item.name = form.name.data item.price = form.price.data item.category = form.category.data item.photo_url = form.photo_url.data item.store = form.store.data db.session.commit() flash("Item information was Updated!") return redirect(url_for('main.item_detail', item_id=item_id)) item = GroceryItem.query.get(item_id) return render_template('item_detail.html', item=item, 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("New item successfully 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(): item.name = (form.name.data) item.price = (form.price.data) item.category = (form.category.data) item.photo_url = (form.photo_url.data) item.store = (form.store.data) db.session.add(item) db.session.commit() flash('A new Grocery Item was successfully updated') item = GroceryItem.query.get(item_id) return render_template('item_detail.html', item=item, form=form)
def item_detail(item_id): item = GroceryItem.query.get(item_id) form = GroceryItemForm(obj=item) if form.validate_on_submit(): item.name = form.name.data item.price = form.price.data item.category = form.category.data item.photo_url = form.photo_url.data item.store = form.store.data db.session.add(item) db.session.commit() flash('Item was updated successfully.') return redirect(url_for('main.item_detail', item_id=item.id)) # TODO: Send the form to the template and use it to render the form fields return render_template('item_detail.html', item=item, 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(): #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(): 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 item_detail(item_id): item = GroceryItem.query.get(item_id) # Created a GroceryItemForm and passed in `obj=item` form = GroceryItemForm(obj=item) if form.validate_on_submit(): item.name=form.name.data item.price=form.price.data item.category=form.category.data item.photo_url=form.photo_url.data item.store=form.store.data db.session.add(item) db.session.commit() flash('You have updated the Grocery Item successfully') item = GroceryItem.query.get(item_id) return render_template('item_detail.html', item=item, 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 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 item_detail(item_id): item = GroceryItem.query.get(item_id) groceryItemForm = GroceryItemForm(obj=item) if groceryItemForm.validate_on_submit(): # Update ORM GroceryItem item.name = groceryItemForm.name.data item.price = groceryItemForm.price.data item.category = groceryItemForm.category.data item.photo_url = groceryItemForm.photo_url.data item.store = groceryItemForm.store.data db.session.commit() flash('Success') # Send to updated GroceryItem page (same resource) return redirect(url_for('main.item_detail', item_id=item_id)) item = GroceryItem.query.get(item_id) # Returned on 'GET' return render_template('item_detail.html', item=item, 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(): # 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 item_detail(item_id): # TODO: Create a GroceryItemForm and pass in `obj=item` item = GroceryItem.query.get(item_id) 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(): item.name = form.name.data item.price = form.price.data item.photo_url = form.photo_url.data item.store = form.store.data # db.session.add(item) db.session.commit() flash('Item has been updated!') return redirect(url_for('main.item_detail', item_id=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=item, 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)