示例#1
0
def item(request, nr_item):
	#try:
	#	item = ItemAgenda.objects.get(id=nr_item)
	#except ItemAgenda.DoesNotExist:
	#	raise Http404(u"Este item não existe!")
	item = get_object_or_404(ItemAgenda, pk=nr_item, usuario=request.user)
	if request.method == 'POST':
		form = ItemAgendaForm(request.POST, instance=item)
		if form.is_valid:
			form.save()
			return render(request,'salvo.html',{})	
	else :
		form = ItemAgendaForm(instance=item)
	return render(request, 'item.html', {"form": form})	
示例#2
0
def adiciona(request):
	form = ItemAgendaForm()
	if request.method == 'POST':
		form = ItemAgendaForm(request.POST)
		if form.is_valid():
			#dados = form.cleaned_data
			#item = ItemAgenda(
			#	data = dados['data'],
			#	hora = dados['hora'],
			#	titulo = dados['titulo'],
			#	descricao = dados['descricao']
			#)
			#item.save()
			item = form.save(commit=False)
			item.usuario = request.user
			item.save()
			form.save_m2m()
			return render(request,'salvo.html',{})		
	return render(request, 'adiciona.html', {"form": form})