當前位置: 首頁>>代碼示例>>Python>>正文


Python AnswerForm.save方法代碼示例

本文整理匯總了Python中questions.forms.AnswerForm.save方法的典型用法代碼示例。如果您正苦於以下問題:Python AnswerForm.save方法的具體用法?Python AnswerForm.save怎麽用?Python AnswerForm.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在questions.forms.AnswerForm的用法示例。


在下文中一共展示了AnswerForm.save方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: question_details

# 需要導入模塊: from questions.forms import AnswerForm [as 別名]
# 或者: from questions.forms.AnswerForm import save [as 別名]
def question_details(request, question_key):
    ctx = {}

    question = get_object_or_404(Question, key=question_key)

    if request.method == 'POST':
        user = users.get_current_user()
        if user is None:
            return redirect(users.create_login_url(request.path))

        initial = {
            'author': users.get_current_user(),
            'question': question,
        }
        form = AnswerForm(request.POST, initial=initial)
        if form.is_valid():
            # XXX FIXME - why initial data does not exist in cleaned data?
            form.cleaned_data.update(initial)

            form.save()

            return redirect(reverse('questions_question_list'))
        ctx['answer_form'] = form

    else:
        ctx['answer_form'] = AnswerForm()


    ctx['question'] = question
    return render(request, 'questions/question_details.html', ctx)
開發者ID:kichawa,項目名稱:Archquestions,代碼行數:32,代碼來源:views.py

示例2: add_answer

# 需要導入模塊: from questions.forms import AnswerForm [as 別名]
# 或者: from questions.forms.AnswerForm import save [as 別名]
def add_answer(request, pk):
    context = RequestContext(request)
    registered = False
    if request.method == 'POST':
        answer_form = AnswerForm(data=request.POST, initial={'user': request.user, 'question': pk})
        if answer_form.is_valid():
            answer_form.instance.user = request.user
            answer_form.instance.question = Question.objects.get(id=pk)
            answer_form.save()
            registered = True
        else:
            print answer_form.errors
    else:
        answer_form = AnswerForm()
    return render(request, 'answer/new.html', {
            'answer_form': answer_form, 'registered': registered, 'question': Question.objects.get(id=pk) })
開發者ID:ericak11,項目名稱:questions_app,代碼行數:18,代碼來源:views.py


注:本文中的questions.forms.AnswerForm.save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。