def update(request, id): question = Question.objects.get(id=id) form = QuestionForm(request.POST, instance=question) # print(id) if form.is_valid(): form.save() # print("Hello") return redirect("/show/") return render(request, 'question/edit.html', {'question': question})
def update(request,id): question = Question.objects.get(id=id) if request.method == "POST": form = QuestionForm(request.POST, instance=question) if form.is_valid(): form.save() return redirect(resolve_url('question:detail',id)) else: form = QuestionForm(instance=question) return render(request,'question/update.html',{'form':form,'question':question})
def create(request): if request.method == "POST": # 데이터를 저장 form = QuestionForm(request.POST) if form.is_valid(): form.save() return redirect(resolve_url('question:list')) else: # 사용자에게 폼을 전달 form = QuestionForm() return render(request, 'question/create.html', {'form': form})
def create(request): if request.method == "POST": form = QuestionForm(request.POST) if form.is_valid(): try: form.save() return redirect('/show/') except: pass else: form = QuestionForm() return render(request, 'question/index.html', {'form': form})
def question_edit(request, pk): item = get_object_or_404(Question, pk=pk) form = QuestionForm(request.POST or None, instance=item) if form.is_valid(): post = form.save(commit=False) post.save() # 저장하기 return redirect('/question/' + str(item.id)) return render(request, 'question/question_form.html', {'form':form})
def question_new(request): if request.method == 'POST': form = QuestionForm(request.POST) if form.is_valid(): question = form.save(commit=False) question.author = request.user question.save() return redirect('question:question_detail', pk=question.pk) else: form = QuestionForm() return render(request, 'question/question_form.html', {'form':form})
def create(request): if request.method == "POST": form = QuestionForm(request.POST) if form.is_valid(): question = form.save(commit=False) question.user = request.user question.save() return redirect(resolve_url("question:list")) else: form = QuestionForm() return render(request,'question/create.html',{'form':form})
def create(request): if request.method == "POST": form = QuestionForm(request.POST) if form.is_valid(): data = form.save() messages.success(request, data.title + 'Added Successfully') return redirect("/show/") # else: # messages.error(request, "Unsuccessful") else: form = QuestionForm() return render(request, 'question/index.html', {'form': form})
def question_new(request): if request.POST: form = QuestionForm(request.POST) if form.is_valid(): question = form.save(request.user) return redirect('question_detail', pk=question.id) else: form = QuestionForm() is_hot = False return render( request, 'question/ask.html', {'form': form, 'profile': current_profile(request.user), 'status' : is_hot}, )
def update(request, id): question = Question.objects.get(id=id) form = QuestionForm(request.POST, instance=question) # print(id) if form.is_valid(): data = form.save() # print("Hello") messages.success(request, data.title + 'Updated Successfully') return redirect("/show/") else: # messages.error(request, "Update Failure") return render(request, 'question/edit.html', { 'question': question, 'form': form })
def add_question_html(request): if not request.user.is_authenticated: return redirect('/') if request.POST: aut, _ = Author.objects.get_or_create(name=request.user.username) form = QuestionForm(aut, data=request.POST) if form.is_valid(): question = form.save() return redirect( reverse("one_question_url", kwargs={'m_id': question.pk})) else: print(form.errors) return render(request, 'question/add_question.html', { 'form': form, }) else: form = QuestionForm(author=Author.objects.get(pk=1)) return render(request, 'question/add_question.html', { 'form': form, })