def new_entry(): """ Page for adding a new weight entry """ if not g.user: flash("You must be logged in to view this page") return redirect("/unauthorized") else: form = WeightEntryForm() if form.validate_on_submit(): new_weight_log = WeightEntry( date = form.date.data, weight = form.weight.data, user_id = g.user.id ) g.user.weight_entries.append(new_weight_log) db.session.commit() return redirect('/weightentries/overview') return render_template("weight-entries/new-weight.html", form=form)
def test_user_weight_log(self): """ Does weight entry get added to user's log? """ test_weight = WeightEntry( date = "2021-01-01" weight = 180 user_id = self.uid ) self.u.weight_entries.append(test_weight) db.session.commit() self.assertEqual(len(self.u.weight_entries), 1)