def add(request): if request.method == 'POST': form = AddForm(request.POST) if form.is_valid(): newDate = form.cleaned_data['date'] newWeight = form.cleaned_data['weight'] w = Weight(weight=newWeight, date=newDate, username=request.user.username) w.save() return HttpResponseRedirect('/weight/') else: form = AddForm() t = loader.get_template('templates/weight_add.html') c = RequestContext(request,{ 'form': form, 'user':request.user, }) return HttpResponse(t.render(c))
def test_save_weight(self): weight1 = Weight() weight1.weight = 100 weight1.record_date=timezone.now() weight1.save() weight2 = Weight() weight2.weight = 50 weight2.record_date=timezone.now() weight2.save() saved_weights = Weight.objects.all() self.assertEqual(saved_weights.count(), 2) weight1 = saved_weights[0] weight2 = saved_weights[1] self.assertEqual(weight1.weight, 100) self.assertEqual(weight2.weight, 50)
def test_save_weight(self): weight1 = Weight() weight1.weight = 100 weight1.record_date = timezone.now() weight1.save() weight2 = Weight() weight2.weight = 50 weight2.record_date = timezone.now() weight2.save() saved_weights = Weight.objects.all() self.assertEqual(saved_weights.count(), 2) weight1 = saved_weights[0] weight2 = saved_weights[1] self.assertEqual(weight1.weight, 100) self.assertEqual(weight2.weight, 50)