def dairy_item(request):
    dairyitems = Item.objects.raw(
        'SELECT * FROM aisle_item WHERE category = "Dairy"')
    template_name = 'aisle/dairy.html'
    context = {"dairyitems": dairyitems}
    c = cart()
    if request.is_ajax():
        requestajax = request.POST.get('key')
        requestajaxamount = request.POST.get('amount')
        c.item_list = requestajax
        c.quantity = requestajaxamount
        c.save()
    return render(request, template_name, context)
Exemplo n.º 2
0
def searchresults(request):
    all_items = Item.objects.all()
    flagcheck = False
    html = ''
    captureword = ''
    capturelogo = ''
    captureprice = ''

    c = cart()
    if request.is_ajax():
        requestajax = request.POST.get('key')
        requestajaxamount = request.POST.get('amount')
        c.item_list = requestajax
        c.quantity = requestajaxamount
        c.save()

    query = request.GET['q']
    html = str(query)
    if request.method == 'GET' and query != '':
        for modelitems in all_items:
            if str(query) in (modelitems.item_name).lower():
                flagcheck = True
                captureword = modelitems.item_name
                capturelogo = modelitems.item_logo
                captureprice = modelitems.price
                captureid = modelitems.id

        if (flagcheck):
            context = {
                'all_items': all_items,
                'flagcheck': flagcheck,
                'itemname': captureword,
                'itemprice': captureprice,
                'id': captureid,
                'itemlogo': capturelogo
            }
            return render(request, 'index/search_results.html', context)
        else:
            newcontext = {
                'all_items': all_items,
                'query': html,
                'flagcheck': flagcheck
            }
            return render(request, 'index/search_results.html', newcontext)

    else:
        return render(request, 'index/index.html')
def babycare_item(request):

    c = cart()
    babycareitems = Item.objects.raw(
        'SELECT * FROM aisle_item WHERE category = "Baby Care"')
    template_name = 'aisle/babycare.html'

    context = {"babycareitems": babycareitems}

    if request.is_ajax():
        requestajax = request.POST.get('key')
        requestajaxamount = request.POST.get('amount')
        c.item_list = requestajax
        c.quantity = requestajaxamount
        c.save()
        #return render(request, 'aisle/beverages.html')

    return render(request, template_name, context)