def note_update_view(request, pk): note = get_object_or_404(Note, pk=pk) if request.method == "GET": form = NoteForm(initial={ 'title': note.title, 'description': note.description, 'text': note.text, 'todo_at': note.todo_at, 'status': note.status, }) return render(request, 'note_update.html', context={ 'form': form, 'note': note }) elif request.method == 'POST': form = NoteForm(data=request.POST) if form.is_valid(): note.title = form.cleaned_data['title'] note.description = form.cleaned_data['description'] note.text = form.cleaned_data['text'] note.todo_at = form.cleaned_data['todo_at'] note.status = form.cleaned_data['status'] note.save() return redirect('note_view', pk=note.pk) else: return render(request, 'note_update.html', context={ 'note': note, 'form': form }) else: return HttpResponseNotAllowed(permitted_methods=['GET', 'POST'])
def note_update_view(request, pk): note = get_object_or_404(Note, id=pk) if request.method == 'GET': form = NoteForm(initial={ 'name': note.name, 'email': note.email, 'text': note.text }) return render(request, 'note_update.html', context={ 'note': note, 'form': form }) elif request.method == 'POST': form = NoteForm(data=request.POST) if form.is_valid(): note.name = form.cleaned_data.get('name') note.email = form.cleaned_data.get('email') note.text = form.cleaned_data.get('text') note.save() return redirect('note-list') return render(request, 'note_update.html', context={ 'form': form, 'task': note })
def note_update_view(request, pk): note = get_object_or_404(Note, pk=pk) if request.method == 'GET': form = NoteForm( data={ 'author_name': note.author_name, 'author_mail': note.author_mail, 'text': note.text }) return render(request, 'update.html', context={ 'note': note, 'form': form }) elif request.method == 'POST': form = NoteForm(data=request.POST) if form.is_valid(): note.author_name = form.cleaned_data['author_name'] note.author_mail = form.cleaned_data['author_mail'] note.text = form.cleaned_data['text'] note.save() return redirect('index') else: return render(request, 'update.html', context={ 'form': form, 'note': note })
def note_create_view(request, *args, **kwargs): if request.method == 'GET': form = NoteForm() return render(request,'note_create.html', context={'form': form}) elif request.method == 'POST': form = NoteForm(data=request.POST) if form.is_valid(): data = form.cleaned_data Note.objects.create(name=data['name'], mail=data['mail'], text=data['text']) return redirect('index') else: return render(request, 'note_create.html', context={'form':form})
def note_create_view(request): if request.method == 'GET': form = NoteForm() return render(request, 'create.html', context={'form': form}) elif request.method == 'POST': form = NoteForm(data=request.POST) if not form.is_valid(): return render(request, 'create.html', context={'form': form}) Note.objects.create(author_name=form.cleaned_data['author_name'], author_mail=form.cleaned_data['author_mail'], text=form.cleaned_data['text']) return redirect('index')
def note_create_view(request): if request.method == "GET": form = NoteForm() return render(request, 'note_create.html', context={ 'choices': status_choices, 'form': form }) elif request.method == "POST": form = NoteForm(data=request.POST) if form.is_valid(): note = Note.objects.create(name=form.cleaned_data.get('name'), email=form.cleaned_data.get('email'), text=form.cleaned_data.get('text')) return redirect('note-list') return render(request, 'note_create.html', context={'form': form})
def note_create_view(request): if request.method == 'GET': return render(request, 'note_create.html', context={ 'form': NoteForm() }) elif request.method == 'POST': form = NoteForm(data=request.POST) if form.is_valid(): note = Note.objects.create( title=form.cleaned_data['title'], description=form.cleaned_data['description'], text=form.cleaned_data['text'], todo_at=form.cleaned_data['todo_at'], status=form.cleaned_data['status']) return redirect('note_view', pk=note.pk) else: return render(request, 'note_create.html', context={'form': form}) else: return HttpResponseNotAllowed(permitted_methods=['GET', 'POST'])