Esempio n. 1
0
def save_product(request):
    if request.method == "POST":
        id = request.POST.get("id")
        product = Product()

        if id:
            name = request.POST.get("name")
            cost = request.POST.get("cost")
            Product.objects.filter(id=id).update(name=name, cost=cost)

        else:
            product.name = request.POST.get("name")
            product.cost = request.POST.get("cost")
            product.save()

    return HttpResponseRedirect("/")
Esempio n. 2
0
def post():
    name = request.form['name']
    print(name)
    location = request.form['location']
    print(location)
    healthy = request.form['healthy']
    print(healthy)
    item = Product()
    item.name = name
    item.healthy = healthy
    item.location = location
    db.session.add(item)
    db.session.commit()
    response = jsonify({
        'message': 'Satllite added',
        'satllite': item.to_json()
    })
    return response
Esempio n. 3
0
def test2():
    user_budget = request.args.get('budget')
    products = []
    message = "あなたの買うべき物を探しました!" + "\n" + "\n"
    budget = 100000
    category = ""

    if user_budget:
        budget = int(user_budget)
    money = budget

    if budget < 10000 or budget > 100000:
        error = Product()
        error.name = "予算が10万円以内でありません"

        return render_template("index.html", products=[error], budget=100000)

    while not products:
        rand = random.randrange(0, db.session.query(Product.id).count())
        products = db.session.query(Product).filter(
            Product.id == rand, Product.price <= budget).all()

    budget -= int(products[0].price)

    while budget > 0:
        candidate = db.session.query(Product).filter(
            Product.price <= budget).all()

        if not candidate:
            break

        product = random.choice(candidate)

        products.append(product)

        budget -= int(product.price)

    return render_template("index.html", products=products, budget=budget)