コード例 #1
0
ファイル: views.py プロジェクト: ferhas/ziai2015
def parentsreg_step2(request):

        if request.method == 'POST': # 如果表单被提交
            form = parentreg2Form(request.POST,request.FILES) # 获取Post表单数据
            if form.is_valid(): # 验证表单
                children = Children()
                children.nicename = form.cleaned_data['nicename']
                children.sex = form.cleaned_data['sex']
                children.bracelet_code = form.cleaned_data['bracelet_code']
                children.attending_school = form.cleaned_data['attending_school']
                children.image_path = request.FILES["image_path"]
                children.save()
                children.Parentskey.add(Parents.objects.get(pk=request.session["parents"]))

                return HttpResponseRedirect('/parentsreg_succeed') # 跳转
        else:
                form = parentreg2Form() #获得表单对象

        return render_to_response('reg/Parentsreg_step2.html', {
                'form': form,
        },context_instance=RequestContext(request))
コード例 #2
0
ファイル: tests.py プロジェクト: ferhas/ziai2015
    def test_Children_number_add(self):
        sch = School(school_name="_name1", classes_number=100)
        sch.save()
 
       
        twz = Classes(class_name="WeizhongTu", children_number=100,schoolkey=sch)
       
        twz.save()
 
        c = Classes.objects.get(pk=1)

        old_number = c.children_number
        children = Children()
        children.Classeskey = c
        children.Parents_id = 1 
        children.nicename = "1"
        children.save() 
        self.assertEqual(children.Classeskey.children_number, 101)
        
 
        children.delete()
        self.assertEqual(children.Classeskey.children_number, 100)
       
        #编辑
        children = Children.objects.get(pk=1)
        children.Classeskey = c
        children.Parents_id = 1 
        children.nicename = "2"
        children.save() 
  
 
        self.assertEqual(children.Classeskey.children_number, 100)