3

My data is not being saved inside the DB.

Here is my views.py file

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()
5
  • are you sure the form.is_valid()? Commented Jul 19, 2013 at 0:06
  • Yes. The form is valid .Prints True when the form is submitted. Commented Jul 19, 2013 at 5:40
  • Any suggestions please!!! Commented Jul 19, 2013 at 5:40
  • Have you overridden save() on CcChatData and WebReply? Commented Jul 19, 2013 at 6:42
  • Can you please elaborate a bit . Thanks Commented Jul 19, 2013 at 9:00

2 Answers 2

3

Try this:

 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)
Sign up to request clarification or add additional context in comments.

Comments

0

Did you check if your form is indeed valid? (is_valid)

Your current code does nothing when the form isn't valid.

1 Comment

Yes. The form is valid .Prints True when the form is submitted. Any suggestions please!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.