def addProduct(user, id, unit_name, unit_value, price, quantity):

    print 'Entro BL addProduct'

    product = Product();

    productActual = Product.objects.get(id=id)

    farm = Farm.objects.all()\
        .only('name','latitude','longitude','size','provider__user')\
        .filter(provider__user=user)

    product.image_url = productActual.image_url
    product.description = productActual.description
    product.name = productActual.name
    product.price = price
    product.unit_value = unit_value
    product.unit_name = unit_name
    product.farm = farm[0]
    product.quantity = quantity

    product.save()

    listProduct = get_products_farm(user);

    return listProduct
def register_products(objs):
    products = json.loads(objs)
    print products
    for p in products:
        print p
        product = Product()
        product.name = p['name']
        product.price = p['price']
        product.image_url = p['image_url']
        product.unit_value = p['unit_value']
        product.unit_name = p['unit_name']
        farm = Farm.objects.get(id=p['farm'])
        product.farm = farm
        product.description = p['description']
        product.quantity = p['quantity']
        product.save()
        print 'objeto guardado'