Пример #1
0
def add_producto_view(request):
	if request.method == "POST":
		form = addProductoForm(request.POST)
		if form.is_valid():
			add = form.save(commit = False)
			add.save()
			messages.success(request, 'Se creó el producto.')
			return HttpResponseRedirect(reverse('list_producto_view'))
		else:
			messages.error(request, 'Ingresa todos los campos.')
	else:
		form = addProductoForm()
	context = {'form': form}

	return render_to_response('admin/producto/add.html', context, context_instance = RequestContext(request))
Пример #2
0
def edit_producto_view(request, id):
	try:
		p = producto.objects.get(id = id)
	except producto.DoesNotExist:
		raise Http404

	if request.method == "POST":
		form = addProductoForm(request.POST, instance = p)
		if form.is_valid():
			edit = form.save(commit = False)
			edit.save()
			messages.success(request, 'Se actualizó el producto.')
		else:
			messages.error(request, 'Ingresa todos los campos.')

	if request.method == "GET":
		form = addProductoForm(instance = p)

	context = {'form': form, 'producto': p}
	return render_to_response('admin/producto/edit.html', context, context_instance = RequestContext(request))