Ejemplo n.º 1
0
def write(request):
    if request.method == 'POST':
        form = QuestionForm(request.POST)
        if form.is_valid():
            question = Question()
            question.create_user = request.user
            question.title = form.cleaned_data.get('title')
            question.content = form.cleaned_data.get('content')
            status = form.cleaned_data.get('status')
            if status in [Question.PUBLISHED, Question.DRAFT]:
                question.status = form.cleaned_data.get('status')
            question.save()
            tags = form.cleaned_data.get('tags')
            question.create_tags(tags)
            return redirect('/questions/')
    else:
        form = QuestionForm()
    return render(request, 'questions/write.html', {'form': form})
Ejemplo n.º 2
0
def write(request):
    if request.method == 'POST':
        form = QuestionForm(request.POST)
        if form.is_valid():
            question = Question()
            question.create_user = request.user
            question.title = form.cleaned_data.get('title')
            question.content = form.cleaned_data.get('content')
            status = form.cleaned_data.get('status')
            if status in [Question.PUBLISHED, Question.DRAFT]:
                question.status = form.cleaned_data.get('status')
            question.save()
            tags = form.cleaned_data.get('tags')
            question.create_tags(tags)
            return redirect('/questions/')
    else:
        form = QuestionForm()
    return render(request, 'questions/write.html', {'form': form})