def add_plato_view(request): if request.method == "POST": form = addPlatoForm(request.POST, request.FILES) if form.is_valid(): add = form.save(commit = False) #handle_uploaded_file(request.FILES['foto']) add.save() form.save_m2m() messages.success(request, 'Se creó el plato.') return HttpResponseRedirect(reverse('list_plato_view')) else: messages.error(request, 'Ingresa todos los campos.') else: form = addPlatoForm() context = {'form': form} return render_to_response('admin/plato/add.html', context, context_instance = RequestContext(request))
def edit_plato_view(request, id): try: p = plato.objects.get(id = id) except plato.DoesNotExist: raise Http404 if request.method == "POST": form = addPlatoForm(request.POST, request.FILES, instance = p) if form.is_valid(): edit = form.save(commit = False) form.save_m2m() edit.save() messages.success(request, 'Se actualizó el plato.') else: messages.error(request, 'Ingresa todos los campos.') if request.method == "GET": form = addPlatoForm(instance = p) context = {'form': form, 'plato': p} return render_to_response('admin/plato/edit.html', context, context_instance = RequestContext(request))