[Fixed]-How can i save ModelForm data to database

1👍

thanks for all the suggestions guys, I finally Got it to work.
here is the working view code which was the major problem

def uploadQpapers(request):
    context = RequestContext(request)
    Qpapers = QuestionBankForm(request.POST, request.FILES)
    if request.method == 'POST':


       if Qpapers.is_valid():

           Upload_Qpapers = Qpapers.save(commit=False)

           if 'question_papers' in request.FILES:
               Upload_Qpapers.question_papers = request.FILES['question_papers']
               Qpapers.save()

           return HttpResponse("ALL GOOD DATA SAVED")
       else:
           return HttpResponse("NOT GOOD")

    else:
        Qpapers = QuestionBankForm()
        return render_to_response("Qbank/uploadQpapers.html", {'Qpapers':Qpapers}, context)

my previous code was missing the quest.FILES, and i wasnt saving the uploaded files seperately
i do hope this solution help another beginner like me in the future

👤jids

Leave a comment