Ejemplo n.º 1
0
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})
Ejemplo n.º 2
0
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})
Ejemplo n.º 3
0
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})
Ejemplo n.º 4
0
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})
Ejemplo n.º 5
0
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})
Ejemplo n.º 6
0
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})
Ejemplo n.º 7
0
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})
Ejemplo n.º 8
0
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})
Ejemplo n.º 9
0
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},
	)
Ejemplo n.º 10
0
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
        })
Ejemplo n.º 11
0
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,
        })