def checkin(request): data = request.JSON form = CheckinForm(data) if form.is_valid(): form.save() return HttpResponse() else: return HttpResponseBadRequest()
def index(request): if request.method == 'POST': form = CheckinForm(request.POST, request.FILES) if form.is_valid(): date = form.cleaned_data['date'] weight = form.cleaned_data['weight'] checkin = Checkin(date=date,weight=weight,photo=request.FILES['photo']) checkin.save() return HttpResponseRedirect('/') else: form = CheckinForm() return render(request, 'index.html', {'checkins': Checkin.objects.all(), 'form': form})
def test_valid_data_saves(self): form = CheckinForm(self.valid_data()) form.is_valid() checkin = form.save() self.assertTrue(checkin.pk)
def test_valid_data(self): form = CheckinForm(self.valid_data()) self.assertTrue(form.is_valid())