本文整理匯總了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)
示例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) })