def nuevo_stock(request):
    if request.method == 'POST':
        formulario = FormStock(request.POST, request.FILES)
        if formulario.is_valid():
            formulario.save()
            return HttpResponseRedirect('/stock')# nos nmanda al index
    else:
        formulario = FormStock()
    return render_to_response('producto/nuevo_produc.html', {'formulario': formulario}, context_instance=RequestContext(request))
def Crear_Producto(request):
    if request.user.is_authenticated():
        if request.method == 'POST':
            formularioproducto = ProductoForm(request.POST, request.FILES)
            formulariostock = FormStock(request.POST)
            if formularioproducto.is_valid() and formulariostock.is_valid():
                pro = formularioproducto.save()
                stock = formulariostock.save()
                stock.reg_pro=pro
                stock.save()
                return HttpResponseRedirect('/categorias/')
        else:
            formularioproducto = ProductoForm()
            formulariostock = FormStock()
        return render_to_response('producto/nuevo_produc.html', {'formularioproducto':formularioproducto, 'formulariostock':formulariostock}, context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect('/')
def Modificar_Producto(request, id_prod):
    if request.user.is_authenticated():
        stocks = get_object_or_404(Stock,pk = id_prod)
        productos = get_object_or_404(Producto, pk=id_prod)
        if request.method == 'POST':
            formulario = ProductoForm(request.POST, request.FILES, instance=productos)
            formulariostock = FormStock(request.POST,request.FILES,instance=stocks)
            if formulario.is_valid()and formulariostock.is_valid():
                formulario.save()
                formulariostock.save()
                return HttpResponseRedirect('/categorias/')
        else:
            formulario = ProductoForm(instance=productos)
            formulariostock = FormStock(instance=stocks)
        return render_to_response('producto/modifica_produc.html', {'formulario': formulario,'formulariostock':formulariostock},context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect('/')