Example #1
0
def ask(request):
    if request.method == 'POST':
        form = QuestionForm(request.POST)
        if form.is_valid():
            question = Question()
            question.user = request.user
            question.title = form.cleaned_data.get('title')
            question.description = form.cleaned_data.get('description')
            caretaker = QuestionCareTaker()
            caretaker.question = question
            caretaker.save()
            question.caretaker = caretaker
            question.save()
            question.caretaker.save()
            tags = form.cleaned_data.get('tags')
            question.create_tags(tags)
            return redirect('/questions/')

        else:
            return render(request, 'questions/ask.html', {'form': form})

    else:
        form = QuestionForm()

    return render(request, 'questions/ask.html', {'form': form})
Example #2
0
def ask(request):
    # 提问按钮
    if request.method == 'POST':
        # post是提交问题
        form = QuestionForm(request.POST)
        if form.is_valid():
            question = Question()
            question.user = request.user
            question.title = form.cleaned_data.get('title')
            question.description = form.cleaned_data.get('description')
            question.save()
            tags = form.cleaned_data.get('tags')
            question.create_tags(tags)

            # 重定向到提问页面
            return redirect('/questions/')

        else:
            return render(request, 'questions/ask.html', {'form': form})

    else:
        # get是显示提问页面
        form = QuestionForm()

    return render(request, 'questions/ask.html', {'form': form})
Example #3
0
def ask(request):
    if request.method == "POST":
        form = QuestionForm(request.POST)
        if form.is_valid():
            question = Question()
            question.user = request.user
            question.title = form.cleaned_data.get("title")
            question.description = form.cleaned_data.get("description")
            question.save()
            tags = form.cleaned_data.get("tags")
            question.create_tags(tags)
            return redirect("/questions/")
        else:
            return render(request, "questions/ask.html", {"form": form})
    else:
        form = QuestionForm()
    return render(request, "questions/ask.html", {"form": form})
Example #4
0
def ask(request):
    if request.method == 'POST':
        form = QuestionForm(request.POST)
        if form.is_valid():
           question = Question()
           question.user = request.user
           question.title = form.cleaned_data.get('Titel')
           question.description = form.cleaned_data.get('Beschreibung')
           question.save()
           tags = form.cleaned_data.get('Schlagworte')
           question.create_tags(tags)
           return redirect('/questions/')
        else:
            return render(request, 'questions/ask.html', {'form': form})
    else:
        form = QuestionForm()
    return render(request, 'questions/ask.html', {'form': form})