如果有一个问答系统,其中答案表格包含在问题模板中,(就像 facebook 帖子评论一样)是否有另一种方法可以保存每个问题的评论?我怎样才能得到问题的ID?
我的代码:
{%include "replies/replies.html"%} #thats in the template where questions are listed
save_question 视图
def save_reply(request, id):
question = New.objects.get(pk = id)
if request.method == 'POST':
form = ReplyForm(request.POST)
if form.is_valid():
new_obj = form.save(commit=False)
new_obj.creator = request.user
u = New.objects.get(pk=id)
new_obj.reply_to = u
new_obj.save()
return HttpResponseRedirect('/accounts/private_profile/')
else:
form = ReplyForm()
return render_to_response('replies/replies.html', {
'form': form,
'question':question,
},
context_instance=RequestContext(request))
和形式:
<form action="." method="post">
<label for="reply"> Comment </label>
<input type="text" name="post" value="">
<p><input type="submit" value="Comment" /></p>
</form>
我怎样才能让这个表格“嵌入”到问题模板中,我怎样才能让它“知道”它所指的问题的ID?
谢谢