Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
DJANGO将数据插入表单字段_Django_Django Models_Django Forms - Fatal编程技术网

DJANGO将数据插入表单字段

DJANGO将数据插入表单字段,django,django-models,django-forms,Django,Django Models,Django Forms,我试图做到的是,如果满足以下条件,在我的字段中插入“是”一词 如果K8Points.objects.filter(student\u name=studentpsid).exists()和K8Points.objects.filter(time\u frame='9:30AM-10:00AM')。exists()和grand\u total>=20: 然后在字段中填入“是”。该表单被视为有效,并将保存。我该怎么做?谢谢 完整代码 def Student_Progress(request, s

我试图做到的是,如果满足以下条件,在我的字段中插入“是”一词


如果K8Points.objects.filter(student\u name=studentpsid).exists()和K8Points.objects.filter(time\u frame='9:30AM-10:00AM')。exists()和grand\u total>=20:

然后在字段中填入“是”。该表单被视为有效,并将保存。我该怎么做?谢谢

完整代码

def Student_Progress(request, studentpsid):
        if request.method == 'POST':
           form = K8Points_Score(request.POST)
           studentid = Student.objects.get(studentpsid=studentpsid)
           date = datetime.date.today()
           academic = K8Points.objects.values_list('academic', flat = True).filter(student_name_id=studentpsid)
           behavior = K8Points.objects.values_list('behavior', flat = True).filter(student_name_id=studentpsid)
           academic_total = 0
           behav_total = 0
           for score in academic: 
                academic_total += int(score)
           for score in behavior:
                behav_total += int(score)

           grand_total = academic_total + behav_total    
           counseling = Student.objects.values_list('counseling_goal', flat = True).get(studentpsid=studentpsid)
           if K8Points.objects.filter(student_name=studentpsid).exists() and K8Points.objects.filter(time_frame='9:30AM - 10:00AM' ).exists() and grand_total >= 20:  
                if form.is_valid():
                   morning_recess = form.cleaned_data.get(morning_recess= "YES") 
                   form.save
                   return render(request, 'points/student_progress.html', {'form': form,'studentid': studentid ,'date':date, 'counseling': counseling, 'grand_total':grand_total, 'academic_total': academic_total, 'behav_total': behav_total,'morning_recess': morning_recess } ) 

                elif K8Points.objects.filter(student_name=studentpsid).exists():
                   form = K8Points_Score()  
                   studentid = Student.objects.get(studentpsid=studentpsid)
                   date = datetime.date.today()
                   academic = K8Points.objects.values_list('academic', flat = True).filter(student_name_id=studentpsid)
                   behavior = K8Points.objects.values_list('behavior', flat = True).filter(student_name_id=studentpsid)
                   academic_total = 0
                   behav_total = 0
                   for score in academic: 
                     academic_total += int(score)
                   for score in behavior:
                     behav_total += int(score)

                   grand_total = academic_total + behav_total    
                   counseling = Student.objects.values_list('counseling_goal', flat = True).get(studentpsid=studentpsid)
                   return render(request, 'points/student_progress.html', {'form':form , 'studentid': studentid ,'date':date, 'counseling': counseling, 'grand_total':grand_total, 'academic_total': academic_total, 'behav_total': behav_total,  } ) 
        else:
            return render(request,'points/student_progress_none.html' )

应该是
form.save()
所以form.save()是个问题,但是,我的代码仍然不起作用。morning\u recurse=K8\u Points.objects.get(morning\u recurse='morning\u recurse')这一行是错误的。如果if语句为真,我要做的是在表单字段中插入YES。