本文整理匯總了Python中forms.QuestionForm.save_m2m方法的典型用法代碼示例。如果您正苦於以下問題:Python QuestionForm.save_m2m方法的具體用法?Python QuestionForm.save_m2m怎麽用?Python QuestionForm.save_m2m使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類forms.QuestionForm
的用法示例。
在下文中一共展示了QuestionForm.save_m2m方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: questions_edit
# 需要導入模塊: from forms import QuestionForm [as 別名]
# 或者: from forms.QuestionForm import save_m2m [as 別名]
def questions_edit(request, instance_pk=None):
if instance_pk is not None:
instance = get_object_or_404(Question, pk=instance_pk)
else:
instance = None
if request.method == 'POST':
form = QuestionForm(request.POST, instance=instance)
if form.is_valid():
question = form.save(commit=False)
question.user = request.user
question.save()
#
form.save_m2m()
# return a message
messages.success(request, 'Question Created')
# return a redirect
return HttpResponseRedirect(reverse('journals:journal_today'))
if request.method == 'GET':
form = QuestionForm(instance=instance)
return render_to_response('journals/questions_edit.html', RequestContext(request,{
'form' : form,
'instance' : instance,
}))