def articulosregistrar(request): if request.method == 'POST': formulario = ArticuloForm(request.POST) if formulario.is_valid(): formulario.save() ultimo = Articulo.objects.latest('id') ultimo.preciototalref = ultimo.sactual * ultimo.precioref ultimo.save() return HttpResponseRedirect('/almacen/articulos/') else: formulario = ArticuloForm(auto_id=True) return render_to_response('articuloseditar.html',{'formulario':formulario},context_instance=RequestContext(request))
def articuloseditar(request, articulo_id): dato = get_object_or_404(Articulo, pk=articulo_id) if request.method == 'POST': formulario = ArticuloForm(request.POST, instance=dato) if formulario.is_valid(): formulario.save() modificar = Articulo.objects.get(pk=articulo_id) modificar.preciototalref = modificar.sactual * modificar.precioref modificar.save() redireccion = '/almacen/articulos/detalle/'+str(articulo_id) return HttpResponseRedirect(redireccion) else: formulario = ArticuloForm(instance=dato) return render_to_response('articuloseditar.html',{'formulario':formulario},context_instance=RequestContext(request))