3

我的数据没有保存在数据库中。

这是我的views.py文件

def rr_reply(request):


    cc_user = request.user.id
    conversation_id = request.GET.get('conversation_id','')
    b_id = request.GET.get('b_id','')


    if request.method == 'POST': 
        form = CcReply(request.POST) 
        if form.is_valid():
            date_time = datetime.datetime.now()
            reply = form.cleaned_data['reply']

            queries = WebQuery.objects.using('launchg').filter(conversation_id = conversation_id)

            for query in queries:
                q_id = query.query_id               

            cc_chat_data_obj = CcChatData(conversation_id = conversation_id , reply_from = request.user.id , 
                b_id = b_id, q_id = q_id)
            web_reply_obj = WebReply(query_id = q_id, conversation_id = conversation_id , b_id = b_id, 
                u_query = reply , date_time = date_time.strftime("%Y-%m-%d %H:%M:%S"),diff = 0)

            cc_chat_data_obj.save()
            web_reply_obj.save()


    else:
        form = CcReply()
4

2 回答 2

3

尝试这个:

 cc_chat_data_obj = CcChatData.objects.create(conversation_id = conversation_id , reply_from = request.user.id , b_id = b_id, q_id = q_id)
 web_reply_obj = WebReply.objects.create(query_id = q_id, conversation_id = conversation_id , b_id = b_id, u_query = reply , date_time = date_time.strftime("%Y-%m-%d %H:%M:%S"),diff = 0)
于 2013-07-19T16:23:27.117 回答
0

您是否检查过您的表格是否确实有效?(已验证)

当表单无效时,您当前的代码不执行任何操作。

于 2013-07-18T23:58:03.147 回答