コード例 #1
0
ファイル: views.py プロジェクト: gzpgg3x/BrowsingOR
def question_edit(request, question_id):
    question = get_object_or_404(Question, pk=question_id)
    if request.method == 'POST':
        form = QuestionForm(request.POST, instance=question)
        if form.is_valid():
            form.save()
            con = lite.connect('C:/Users/fpan/PY-Programs/BrowsingOR/jumpingintodjango/jumpingintodjango/db/db.sqlite')
            cur = con.cursor()
            for row in cur.execute("SELECT * FROM questionsandanswers_question WHERE id=?", question_id):
                a = row[0]
                b = row[3]
                # print a
                # print b

            con = lite.connect('C:/Users/fpan/PY-Programs/BrowsingOR/jumpingintodjango/jumpingintodjango/db/db.sqlite')

            with con:
    
                cur = con.cursor()

                lid = cur.execute('SELECT max(id) FROM questionsandanswers_answer')
                max_id = lid.fetchone()[0] + 1

                # lid = cur.lastrowid 
                print max_id
                #c = int(lid) + 1
                cur.execute("INSERT INTO questionsandanswers_answer VALUES(?,?,?,?)",(max_id,b,a,a))
                con.commit()
                # print a
                # print b

            return redirect('question_detail', question_id)
    else:
        form = QuestionForm(instance=question)
        return render_to_response('question_edit.html',{'form': form},context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: nicmatts/jumpintodjango
def question_create(request):
	if request.method == 'POST':
		form = QuestionForm(request.POST)
		if form.is_valid():
			form.save()
			return redirect('/questions')	
	else:
		form = QuestionForm()
	return render_to_response('questionsandanswers/question_create.html', {'form': form}, context_instance=RequestContext(request))
コード例 #3
0
ファイル: views.py プロジェクト: nicmatts/jumpintodjango
def question_edit(request, question_id):
	question = get_object_or_404(Question, pk=question_id)
	if request.method=='POST':
		form = QuestionForm(request.POST, instance=question)
		if form.is_valid():
			form.save()
			return redirect('question_detail', question_id)
	else:
		form = QuestionForm(instance=question)
	return render_to_response('questionsandanswers/question_edit.html', {'form': form}, context_instance=RequestContext(request))