def edit_tipo(request, tipo): t = find_model(request,tipo,SubCategoria) if request.POST: f = SubCategoriaForm(request.POST,instance = t) if f.is_valid(): f.save() return HttpResponseRedirect(reverse('list_tipos')) else: return render_to_response("gastos/tipo_form.html", dict(form=f)) else: f = SubCategoriaForm(instance = t) return render_to_response("gastos/tipo_form.html", dict(form=f), context_instance=RequestContext(request) )
def add_tipo(request): if request.POST: formtipo = SubCategoriaForm(request.POST) if formtipo.is_valid(): tip = formtipo.save(commit=False) tip.user = request.user tip.save() return HttpResponseRedirect(reverse('list_tipos')) else: return render_to_response("gastos/tipo_form.html", dict(form=formtipo) ) else: formtipo = SubCategoriaForm() return render_to_response("gastos/tipo_form.html", dict(form=formtipo), context_instance=RequestContext(request) )