def edit_gasto(request, id): g = find_model(request,id,Gasto) if request.POST: gastoform = GastoForm(request.user, request.POST, instance = g) if not gastoform.is_valid(): return render_to_response("gastos/gasto_form.html", dict(form = gastoform), context_instance=RequestContext(request)) else: gast = gastoform.save(commit=False) gast.save() gastoform.save_m2m() return HttpResponseRedirect(reverse('index')) else: gastoform = GastoForm(request.user, instance = g ) return render_to_response("gastos/gasto_form.html", dict(form = gastoform), context_instance=RequestContext(request) )
def add_gasto(request): if request.POST: gastoform = GastoForm(request.user, request.POST) if not gastoform.is_valid(): return render_to_response("gastos/gasto_form.html", dict(form = gastoform),context_instance=RequestContext(request)) else: gast = gastoform.save(commit=False) gast.user = request.user gast.save() gastoform.save_m2m() return HttpResponseRedirect(reverse('index')) else: gastoform = GastoForm(request.user) return render_to_response("gastos/gasto_form.html", dict(form = gastoform), context_instance=RequestContext(request) )