相关疑难解决方法(0)

如何使用django表单编辑模型数据

我是django的新手,所以我很抱歉我的新手问题
我有一个模型,我需要让用户使用django表单或任何其他方式编辑其中的数据. 在此输入图像描述

看看上面的图片,我想显示这个表格已准备好填充数据并让用户更新它.
做这个的最好方式是什么 ?

编辑:这是我的views.py代码

def exam_Edit(request,examName,number=0):
    numner = int(number)
    number = int(number)
    questionNo = int(numner)
    Myexam = models.Exam.objects.get(name = examName)



    QuestionsAll = models.Question.objects.filter(exam = Myexam)

    myQeustion = Question.objects.filter(exam = Myexam)[nextQuestion]

    answer1 =  models.Asnwers.objects.filter(question=myQeustion)[0]
    answer2 =  models.Asnwers.objects.filter(question=myQeustion)[1]
    answer3 =  models.Asnwers.objects.filter(question=myQeustion)[2]
    answer4 = models.Asnwers.objects.filter(question=myQeustion)[3]


    # HERE IS MY PROBLEM : the line below creates a form with a data but it doesn't save it to the save object     
    form = QuestionsEditForm(initial = {'questionText':myQeustion.__unicode__() , 'firstChoiceText':answer1.__unicode__(),'secondChoiceText':answer2.__unicode__(),'thirdChoiceText':answer3.__unicode__(),'forthChoiceText':answer4.__unicode__()})

    if request.method =='POST':
        #if post …
Run Code Online (Sandbox Code Playgroud)

python django django-forms

19
推荐指数
1
解决办法
3万
查看次数

标签 统计

django ×1

django-forms ×1

python ×1