示例#1
0
def adiciona(request):
	if request.method == "POST":
		form = FormItem(request.POST, request.FILES)
		if form.is_valid():
			item = form.save(commit=False)
			item.usuario = request.user
			item.save()
			form.save_m2m()
			return render_to_response("salvo.html", {})
	else:
		form = FormItem()
	return render_to_response("adiciona.html", {'form': form}, 
		context_instance= RequestContext(request))
示例#2
0
def item(request, nr_item):
	item = get_object_or_404(Item, pk = nr_item, usuario = request.user)
	if request.method == "POST":
		form = FormItem(request.POST, request.FILES, instance = item)
		if form.is_valid():
			item = form.save(commit=False)
			item.usuario = request.user
			item.save()
			form.save_m2m()
			return render_to_response("salvo.html", {})
	else:
		form = FormItem(instance=item)
	return render_to_response("item.html", {'form': form},
		context_instance = RequestContext(request))