Esempio n. 1
0
def update_products(request, id):
    data = request.json
    update = Products.objects(id=id)[0]
    update.name = data['name']
    update.description = data['description']
    # update.precio = data['precio']
    update.save()

    return response.json(update.to_json())
Esempio n. 2
0
def add_products(request):
    
    data = request.json

    pro = Products.objects(name=data['name'])
    
    if len(pro) == 0:
        newProduct = Products(name= data['name'], description=data['description'], precio=data['precio'])
        newProduct.save()

    return response.json({
        "data": data
    })
Esempio n. 3
0
def get_products(request):
    results_redis = redis.get(list_products_redis)
    if not results_redis:
        data = []

        productos = Products.objects()

        if len(productos) > 0:
            for producto in productos:
                _id = producto.id

                data.append({"_id": str(_id), "name": producto.name, "description": producto.description})
                redis.setex(list_products_redis, 10 , str(data))
        
            return response.json({ "data": data})
    else:
        return response.json({ "data": json.loads(results_redis)})
Esempio n. 4
0
def remove_products(request, id):
    Products.objects(id=id).delete()
    return response.json({
    })