类型对象' StudentPerformance'没有属性'对象'

时间:2017-06-19 06:04:55

标签: python django

这是我的代码 models.py

class StudentPerformance(models.Model):
    student_activity=models.ForeignKey(StudentsActivity,db_index=True)
    student_subactivity=models.ForeignKey(StudentSubactivity,db_index=True)
    student_detail=models.ForeignKey(StudentDetail,db_index=True)
    grade_section=models.ForeignKey(UnitGradeSection,db_index=True)
    date=models.DateField(blank=True,null=True)
    venue=models.CharField(max_length=250,blank=True,null=True)
    remarks=models.CharField(max_length=250,blank=True,null=True)

Views.py

class StudentActivity(LoginRequiredMixin,TemplateView):
    template_name="student/student_activity.html"
    form_class2=PerformanceForm

    def get_context_data(self,*args,**kwargs):
        context=super(StudentActivity,self).get_context_data(*args,**kwargs)
        context['stud']=StudentDetail.objects.get(id=self.kwargs['stu_id'])
        context['vaccination']=VaccineMaster.objects.all()
        context['activity']=StudentsActivity.objects.all()
        context['subactivity']=StudentSubactivity.objects.all()
        context['form']=self.form_class
        context['form1']=self.form_class1
        context['form2']=self.form_class2
        return context

    def post(self,request,*args,**kwargs):
        self.context=super(StudentActivity,self).get_context_data(*args,**kwargs)


        if 'save' in request.POST:
            stu_ids=request.POST.get('stud_id[]')
            grade_ids=request.POST.get('grade_id[]')
            act=request.POST.get('act') 
            subact=request.POST.get('sub')
            form=self.form_class2(self.request.POST)
            if form.is_valid():
                date=form['date'].data
                venue=form['venue'].data
                remark=form['remarks'].data
                d=datetime.strptime(date,'%d-%m-%Y')

                perform,created=StudentPerformance.objects.get_or_create(student_activity_id=act,student_subactivity_id=subact,student_detail_id=stu_ids,grade_section_id=grade_ids,date=d,venue=venue,remarks=remark)
                if created:
                    messages.success(request,'Details Entered Successfully')
                    return HttpResponseRedirect('/student/student_activity/%s' %self.kwargs['stu_id'])
            else:
                message.error(request,'Nothing To save')
                return HttpResponseRedirect('')

我收到类似"类型对象' StudentPerformance'没有属性'对象'"并且无法将数据保存到数据库。请帮我修复此错误。谢谢。

0 个答案:

没有答案