Exemple #1
0
def item_copy(item_id):
    item = Item.query.get(item_id)
    newItem = Item(item.name)
    newItem.brand = item.brand
    newItem.category = item.category
    newItem.weight = item.weight
    newItem.volume = item.volume
    newItem.description = item.description
    newItem.user_id = current_user.id

    db.session().add(newItem)
    db.session().commit()

    return redirect(url_for("items_index"))
Exemple #2
0
def item_create():
    # New item form
    if request.method=="GET":
        return render_template("items/new.html", form = ItemForm())

    # Form validation
    form = ItemForm(request.form)
    if not form.validate():
        return render_template("items/new.html", form = form)

    # Adding new item to db
    item = Item(form.name.data)
    item.brand = form.brand.data
    item.category = form.category.data
    item.weight = form.weight.data
    item.volume = form.volume.data
    item.description = form.description.data
    item.user_id = current_user.id

    db.session().add(item)
    db.session().commit()

    return redirect(url_for("items_index"))